I have one table (Bigquery), which has ', ' separated values in two columns:
id tag_id tag_name
1 1, 2, 4 a, b, d
2 3 c
3 1, 4 a, d
For each tag_id is 1:1 matched with a tag_name. I want to split the comma separated values and convert them into rows. The ideal output is like:
id tag_id tag_name
1 1 a
1 2 b
1 4 d
2 3 c
3 1 a
3 4 d
My working progress SQL:
SELECT * EXCEPT(t, tn) REPLACE(t AS tag_id, tn AS tags_name)
FROM `table`,
UNNEST(SPLIT(tag_id, ', ')) t, UNNEST(SPLIT(tags_name, ', ')) tn
But it seems that tag_id is not 1:1 matched with tags_name... I'd like to use the EXCEPT in the select query as there are many other columns which I don't want to list them all out manually.