title: SQL::Match duplicate values and concatenate the results in a comma separated string
body: <p>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 .</p>
  
  <pre><code>          u0                       u1    
  1         A                         B 
  2         B                         C
  3         D                         B
  4         B                         D
  5         F                         E
  </code></pre>
  
  <p>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.</p>
  
  <p>Desiered output:</p>
  
  <pre><code>       IDs
  u0    A,B,C,D
  u1    E,F,G
  </code></pre>
  
  <p>The way I have approached the task is with the following : </p>
  
  <pre><code>select 
    distinct 
      stuff((  
          select ',' + u0
          from [db1]
          where u0 like u1 
          for xml path('')
   ),1,1,'')as uids 
  from [db1]
  </code></pre>
  
  <p>But with this query in BigQuery I get the error : </p>
  
  <blockquote>
    <p>Error: Encountered " "FOR" "for "" at line 7, column 9. Was expecting:
    ")" ...</p>
  </blockquote>
  
  <p>I have tried with COALESCE as well , but with no success </p>
  
  <pre><code>SELECT uids = COALESCE(u1 + ',','') + u0
  FROM [db1]
  WHERE u0 in u1
  </code></pre>
  
  <p>and got this error message back : </p>
  
  <blockquote>
    <p>Error: Encountered " "IN" "in "" at line 3, column 12. Was expecting:
    </p>
  </blockquote>
  
  <p>Thank you in advance.</p>