title: How Stuff and 'For Xml Path' work in SQL Server?
body: <p>Table is:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>aaa</td>
  </tr>
  <tr>
  <td>1</td>
  <td>bbb</td>
  </tr>
  <tr>
  <td>1</td>
  <td>ccc</td>
  </tr>
  <tr>
  <td>1</td>
  <td>ddd</td>
  </tr>
  <tr>
  <td>1</td>
  <td>eee</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Required output:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>abc</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>aaa,bbb,ccc,ddd,eee</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Query:</p>
  <pre><code>SELECT ID, 
      abc = STUFF(
                   (SELECT ',' + name FROM temp1 FOR XML PATH ('')), 1, 1, ''
                 ) 
  FROM temp1 GROUP BY id
  </code></pre>
  <p>This query is working properly. But I just need the explanation how it works or is there any other or short way to do this.</p>
  <p>I am getting very confused to understand this.</p>