Substring to return all values ​​after the separator

How do I get all the values ​​after the first separator? In the following example, I expect "xyz @ yahoo.com, pqr @ company.com"

(02:40) mysql>select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  1) as first;
+-----------------+
| first           |
+-----------------+
| abc@hotmail.com |
+-----------------+
1 row in set (0.00 sec)

(02:41) mysql>select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  -1) as last;
+-----------------+
| last            |
+-----------------+
| pqr@company.com |
+-----------------+
1 row in set (0.00 sec)
+3
source share
1 answer
   select substring('abc@hotmail.com,xyz@yahoo.com,pqr@company.com',
   instr('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',') + 1) as first;
+4
source

Source: https://habr.com/ru/post/1762410/


All Articles