I have this column:
names
John, Mary
Joseph
Eleanor, Sophia, Dani
And I want this output:
names
John
Mary
Joseph
Eleanor
Sophia
Dani
And it should include the SUBSTRING_INDEX function
You can use a recursive CTE:
with recursive cte as (
select ' ' as name, concat(names, ',') as names, 1 as lev
from t
union all
select substring_index(names, ',', 1),
substr(names, instr(names, ',') + 2), lev + 1
from cte
where names like '%,%'
)
select name
from cte
where lev > 1;
Here is a db<>fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With