MySQL query to return a substring after delimiter?


Use SUBSTRING() to return values after delimiter. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Title text
   -> );
Query OK, 0 rows affected (0.56 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('John is good in MySQL,Sam is good in MongoDB,Mike is good in Java');
Query OK, 1 row affected (0.19 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-------------------------------------------------------------------+
| Title                                                             |
+-------------------------------------------------------------------+
| John is good in MySQL,Sam is good in MongoDB,Mike is good in Java |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)

Here is the query to return substring after delimiter.

mysql> select substring(Title, instr(Title, ',') + 1) as AfterDelimiter from DemoTable;

This will produce the following output −

+---------------------------------------------+
| AfterDelimiter                              |
+---------------------------------------------+
| Sam is good in MongoDB,Mike is good in Java |
+---------------------------------------------+
1 row in set (0.03 sec)
raja
Published on 12-Jul-2019 11:23:51
Advertisements