title: Loop through all rows and concat unique values in SQL table
body: <p>I have two table that I want to merge. </p>
  
  <p>Table 1 consisting of many rows, below are a few- </p>
  
  <pre><code>col1   col2  col3  col4
  
  val1   val2  val3  val4
  val1   val2  val3  val5
  val1   val2  val3  val6
  valx   valy  valz  val4
  valx   valy  valz  val5
  </code></pre>
  
  <p>(val* are all strings)</p>
  
  <p>Table 2 consists of unique rows (around 1000 of them) - 
      col1   col2  col3  col4</p>
  
  <pre><code>val1   val2  val3  -
  valx   valy  valz  -
  vala   valy  valz  -
  </code></pre>
  
  <p>I want to merge the two tables such that, Table 2 is the following -</p>
  
  <pre><code>col1   col2  col3  col4
  
  val1   val2  val3  val4,val5,val6
  valx   valy  valz  val4,val5
  vala   valy  valz  -
  </code></pre>
  
  <p>Foreach row in table 2, I want to find the unique values for col4 table 1 and concat them</p>