QUERY ERROR - Duplicate alias offset found

40 Views Asked by At

I am trying to use the below logic to get the expected output, but getting error mentioned on my question,

I am trying to unnest multiple columns based on comma delimiter and to avoid duplicates while unnesting it and doing a join to avoid duplicates. when i join 2 columns with offset, i am not seeing any issues , but when doing with more than 2 columns, facing errors.

select Colm_A, Colm_B, Colm_C
from your_table, 
unnest(split(Colm_B)) Colm_B with offset
join unnest(split(Colm_C)) Colm_C with offset join unnest(split(Colm_D)) Colm_D
using (offset);

SOURCE TABLE

Colm_A  Colm_B  Colm_C COL_D
1       Fish     F      H
2       Dog,cat  D,C    G,T

Expected output

Colm_A  Colm_B  Colm_C  COLM_D
1       Fish    F        H
2        Dog    D        G
2        Cat    C        T
1

There are 1 best solutions below

4
Mikhail Berlyant On

Use below

select Colm_A, Colm_B, Colm_C, Colm_D
from your_table, 
unnest(split(Colm_B)) Colm_B with offset as B
join unnest(split(Colm_C)) Colm_C with offset as C on B = C
join unnest(split(Colm_D)) Colm_D with offset as D on B = D

with output

enter image description here