title: SQL "tree-like" query - most parent group
body: <p>I'm having some trouble doing a "tree-like" query (what do we call this?) in SQL.</p>
  
  <p>Take a look at my diagram below (table and column names are in danish - sorry about that):</p>
  
  <p><a href="http://img197.imageshack.us/img197/8721/44060572.jpg" rel="nofollow noreferrer">DB diagram http://img197.imageshack.us/img197/8721/44060572.jpg</a>
  Using MSSQL Server 2005, the goal is to find the <strong>most parent group</strong> (Gruppe), for each customer (Kunde).</p>
  
  <p>Each group can have many parent groups and many child groups.</p>
  
  <p>And, I would also like to know how to display the tree like this:</p>
  
  <pre>
  Customer 1
     - Parent group 1
        - Child group 1
           - ChildChild group n
        - Child group n
     - Parent group n
        - ...
           - ...
  Customer n
     - ...
  </pre>
  
  <hr>
  
  <p>Another question:</p>
  
  <p>How does the query look to get ALL the groups for all the customers? Parent and child groups.</p>