Break comma separated into multiple rows in MYSQL

 Break comma-separated string/column/parameter into multiple rows in MYSQL.

with recursive

    cs_string as ( select 'a,b,c,d' as items),


    cs_rowID as ( select 1 as n union select n + 1 from cs_rowID, cs_string

        where n <= length(items) - length(replace(items, ',', '')))


select distinct substring_index(substring_index(items, ',', n), ',', -1) 

group_name from cs_rowID, cs_string


Output:




Comments

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases

Apply paging in procedure