title: Merge multiple rows into a column while replacing the keys with a 'name' field from the original table
body: <p>I've got a join table that has 'account_id' and 'group id' in it, both represented by a GUID. I'm trying to merge the columns so we get a single 'account_id' with all of it's 'group_id's merged to a single Colum/row, but display the actual name of the account and group.</p>
  <p>Tables
  Account</p>
  <pre><code>account_id   Name
  1            Henry
  2            Smith
  </code></pre>
  <p>Group</p>
  <pre><code>Group_id   Group_nameName
  3            User
  4            Admin
  </code></pre>
  <p>Account_Group_Join_Table</p>
  <pre><code>account_id   group_id
  1            3
  1            4
  2            3
  </code></pre>
  <p>Desired Result:</p>
  <pre><code>Name    Groups
  Henry   Dev,User
  Smith   User, Admin
  </code></pre>
  <p>Code so far to return 'account_id' with 'group_id' grouped to single row/column</p>
  <pre><code>select account_id,
    stuff((SELECT distinct ', ' + group_id
             FROM account_group_join t2
             where t2.account_id = t1.account_id
             FOR XML PATH('')),1,1,'') [Groups]
  from account_group_join t1
  group by account_id
  </code></pre>