title: How to find all connected subgraphs of an undirected graph
body: <p>I need some help for a problem that i am struggling to solve.</p>
  
  <p>Example table:</p>
  
  <pre><code>ID |Identifier1 | Identifier2 
  ---------------------------------
  1  |      a     | c         
  2  |      b     | f         
  3  |      a     | g         
  4  |      c     | h        
  5  |      b     | j         
  6  |      d     | f         
  7  |      e     | k  
  8  |      i     |          
  9  |      l     | h    
  </code></pre>
  
  <p>I want to group identifiers that are related with each other between two columns and assign a unique group id.</p>
  
  <p>Desired Output:</p>
  
  <pre><code>Identifier | Gr_ID    |    Gr.Members                 
  ---------------------------------------------------
  a       |      1      |   (a,c,g,h,l)  
  b       |      2      |   (b,d,f,j)       
  c       |      1      |   (a,c,g,h,l)  
  d       |      2      |   (b,d,f,j)       
  e       |      3      |   (e,k)                 
  f       |      2      |   (b,d,f,j)       
  g       |      1      |   (a,c,g,h,l)  
  h       |      1      |   (a,c,g,h,l)  
  j       |      2      |   (b,d,f,j)       
  k       |      3      |   (e,k)                 
  l       |      1      |   (a,c,g,h,l)  
  i       |      4      |   (i)  
  </code></pre>
  
  <p>Note:the column Gr.Members is not necessary, mostly is used for a clearer view.</p>
  
  <blockquote>
    <p>So the definition for a group is: A row belongs to a group if it
    shares at least one identifier with at least one row of this group</p>
  </blockquote>
  
  <p>But the group id has to be assigned to each identifier(selected by the union of the two columns) not to the row.</p>
  
  <p>Any help on how to build a query to give the desired output?</p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p><strong>Update:</strong> Below are some extra sample sets with their expected output.</p>
  
  <hr>
  
  <p>Given table:</p>
  
  <pre><code>Identifier1 | Identifier2   
  ----------------------------
      a       |   f
      a       |   g
      a       |  NULL
      b       |   c
      b       |   a
      b       |   h
      b       |   j
      b       |  NULL
      b       |  NULL
      b       |   g
      c       |   k
      c       |   b
      d       |   l
      d       |   f
      d       |   g
      d       |   m
      d       |   a
      d       |  NULL
      d       |   a
      e       |   c
      e       |   b
      e       |  NULL
  </code></pre>
  
  <p>Expected output: all the records should belong to the same group with group ID = 1.</p>
  
  <hr>
  
  <p>Given Table:</p>
  
  <pre><code>Identifier1 | Identifier2
  --------------------------
  a           |   a
  b           |   b
  c           |   a
  c           |   b
  c           |   c
  </code></pre>
  
  <p>Expected output: The records should be in the same group with group ID = 1.</p>