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;

Output

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;

Output

This will produce the following output −

+---------------------------------------------+
| AfterDelimiter                              |
+---------------------------------------------+
| Sam is good in MongoDB,Mike is good in Java |
+---------------------------------------------+
1 row in set (0.03 sec)

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 30-Jun-2020

632 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements