By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table mytable as
select 'name1,name2' column1
union all select 'name2,name3'
union all select 'name4,name1,name3'
Records: 3 Duplicates: 0 Warnings: 0
select * from mytable
column1 |
---|
name1,name2 |
name2,name3 |
name4,name1,name3 |
with recursive
data as (select concat(column1, ',') rest from mytable),
words as (
select substring(rest, 1, locate(',', rest) - 1) word, substring(rest, locate(',', rest) + 1) rest
from data
union all
select substring(rest, 1, locate(',', rest) - 1) word, substring(rest, locate(',', rest) + 1) rest
from words
where locate(',', rest) > 0
)
select distinct word from words order by word
word |
---|
name1 |
name2 |
name3 |
name4 |