Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert comma separated string value into rows in MySQL?

I have one column in MySQL which is return me comma separated value , I want to convert that column in to rows.

Better answer then How to convert comma separated parameters to rows in mysql?

select value from table limit 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

response

value
honda,activa,pleasure,car

I want this value to row like

value
honda
activa
pleasure
car

>Solution :

CREATE TABLE response (id INT, value TEXT)
SELECT 1 id, 'honda,activa,pleasure,car' value;
SELECT response.id, jsontable.value
FROM response
CROSS JOIN JSON_TABLE(CONCAT('["', REPLACE(value, ',', '","'), '"]'),
                      '$[*]' COLUMNS (value TEXT PATH '$')) jsontable;
id value
1 honda
1 activa
1 pleasure
1 car

fiddle

PS. The query assumes that the value does not contain duoble quotes. If they are present then they must be quoted. See https://dbfiddle.uk/HUmPZEo1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading