The task I am trying to achieve is the following: I have a table with two columns : - u0 and u1. The values in the two columns sometimes are repeated, meaning that one value would appear in both u0 and u1 .
u0 u1
1 A B
2 B C
3 D B
4 B D
5 F E
If the table has one row: u0=A, u1=B and another row u0=B, u1=C then we can conclude that A,B and C all belong to the same user. The idea is to build a table with a column where every row contains a list of U entries that belong to one user in a comma separated string.
Desiered output:
IDs
u0 A,B,C,D
u1 E,F,G
The way I have approached the task is with the following :
select
distinct
stuff((
select ',' + u0
from [db1]
where u0 like u1
for xml path('')
),1,1,'')as uids
from [db1]
But with this query in BigQuery I get the error :
Error: Encountered " "FOR" "for "" at line 7, column 9. Was expecting: ")" ...
I have tried with COALESCE as well , but with no success
SELECT uids = COALESCE(u1 + ',','') + u0
FROM [db1]
WHERE u0 in u1
and got this error message back :
Error: Encountered " "IN" "in "" at line 3, column 12. Was expecting:
Thank you in advance.