I've a csv file that I imported to my database in which there are a column with comma separated values and what I wanna do is get all the values without duplicates from these column and put it in a only one column
This it's the table
And this it's what I wanna do:
I don't want to modify the original column just show these values in this shape for know all diferentes values that the comma separated strings could take
I think that in this question SQL split values to multiple rows there are the answer. It provides this code:
select
tablename.id,
SUBSTRING_INDEX(SUBSTRING_INDEX(tablename.name, ',', numbers.n), ',', -1) name
from
numbers inner join tablename
on CHAR_LENGTH(tablename.name)
-CHAR_LENGTH(REPLACE(tablename.name, ',', ''))>=numbers.n-1
order by
id, n
But I can't deeply understand it. Why there are two substring_index? What's it's the use of n.numbers? What's the use of "name" keyword? etc.
It would greatly appreciated if someone can clarify me that or if in other question it better explained then in this case this question will can linked to that or borrow