mysql - SQL split values to multiple rows -


i have table :

id | name     1  | a,b,c     2  | b 

i want output :

id | name     1  |     1  | b     1  | c     2  | b 

if can create numbers table, contains numbers 1 maximum fields split, use solution this:

select   tablename.id,   substring_index(substring_index(tablename.name, ',', numbers.n), ',', -1) name   numbers inner join tablename   on char_length(tablename.name)      -char_length(replace(tablename.name, ',', ''))>=numbers.n-1 order   id, n 

please see fiddle here.

if cannot create table, solution can this:

select   tablename.id,   substring_index(substring_index(tablename.name, ',', numbers.n), ',', -1) name   (select 1 n union    select 2 union select 3 union    select 4 union select 5) numbers inner join tablename   on char_length(tablename.name)      -char_length(replace(tablename.name, ',', ''))>=numbers.n-1 order   id, n 

an example fiddle here.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -