title: Tricky T-SQL Query. Concatenate multiple values from a column between master/child tables
body: <p>I have three tables as follows:</p>
  
  <p>MasterTable </p>
  
  <pre><code>+----------+-------------+
  | MasterId | MasterName  |
  +----------+-------------+
  | 1        | Master 1    |
  | 2        | Master 2    |
  | 3        | Master 3    |
  | 4        | Master 4    |
  +----------+-------------+
  </code></pre>
  
  <p>ChildrenTable</p>
  
  <pre><code>+----------+-------------+
  | ChildId | ChildName    |
  +----------+-------------+
  | 1        | Child 1     |
  | 2        | Child 2     |
  | 3        | Child 3     |
  | 4        | Child 4     |
  +----------+-------------+
  </code></pre>
  
  <p>LinkTable</p>
  
  <pre><code>+----------+-----------------------+
  | Id       | MasterId    | ChldId  |
  +----------+-----------------------+
  | 1        |  1          | 1       | 
  | 2        |  2          | 1       | 
  | 3        |  3          | 2       | 
  | 4        |  4          | 3       | 
  +----------+-----------------------+
  </code></pre>
  
  <p>One child can be linked with multiple masters and LinkTable contains this detail. I want a query to select the following:</p>
  
  <pre><code>1, 'Child 1', 'Master 1, Master 2', '1,2'
  2, 'Child 2', 'Master 2', '2'
  3, 'Child 3', 'Master 3', '3'
  </code></pre>
  
  <p>Is it possible to do without loops or calling additional function, using <code>COALESCE</code>, <code>STUFF</code>, recursive <code>CTE</code> etc?</p>