title: Recursive query in SQL Server
body: <p>I have a table with following structure</p>
  
  <p>Table name: <code>matches</code></p>
  
  <p><img src="https://i.stack.imgur.com/cbWoQ.png" alt="Table name: matches"></p>
  
  <p>That basically stores which product is matching which product. I need to process this table
  And store in a groups table like below.</p>
  
  <p>Table Name: <code>groups</code></p>
  
  <p><img src="https://i.stack.imgur.com/jD9Mc.png" alt="enter image description here"></p>
  
  <p><code>group_ID</code> stores the <code>MIN Product_ID</code> of the <code>Product_IDS</code> that form a group. To give an example let's say</p>
  
  <p>If A is matching B and B is Matching C then three rows should go to group table in format <code>(A, A), (A, B), (A, C)</code></p>
  
  <p>I have tried looking into co-related subqueries and CTE, but not getting this to implement. </p>
  
  <p>I need to do this all in SQL. </p>
  
  <p>Thanks for the help .</p>