title: Get distinct values of two columns and merge into rows
body: <p>I have a table named <code>dbo.WebsiteIP</code> having two columns <code>IPAddress</code>, <code>SiteName</code>, and I am doing a bulk insert the values to the this table which look like below</p>
  
  <pre><code>IPAddress       SiteName
  192.168.30.6    website1.domain.com
  192.168.30.6    website2.domain.com
  192.168.30.7    website3.domain.com
  192.168.30.7    website4.domain.com
  192.168.30.7    website5.domain.com
  192.168.30.7    website6.domain.com
  192.168.30.7    website7.domain.com
  192.168.30.8    website8.domain.com
  192.168.30.8    website9.domain.com
  192.168.30.8    website10.domain.com
  192.168.30.8    website11.domain.com
  192.168.30.9    website12.domain.com
  192.168.30.8    website13.domain.com
  192.168.30.8    website14.domain.com
  192.168.30.24   website15.domain.com
  192.168.30.8    website16.domain.com
  192.168.30.8    website17.domain.com
  </code></pre>
  
  <p>I want to do a <em>distinct</em> query for the IP Address and combine the <code>SiteName</code> like below</p>
  
  <pre><code>IPAddress       WebsiteName 
  192.168.30.6    website1, website2,
  192.168.30.7    website3, website4, website5, website6, website7
  192.168.30.8    website8, website9, website10, website11, website13, website14
  192.168.30.9    website12
  192.168.30.24   website15
  </code></pre>
  
  <p>I can able to combine the <code>IPAddress</code> using the below query but <strong>how to combine the appropriate <code>Sitename</code> to the IP Address.</strong></p>
  
  <pre><code>Update Table1
  Set IP= (Select IPAddress + ',' + ' '
  From dbo.WebsiteIP
  GROUP BY IPAddress FOR XML PATH(''))
  GO
  </code></pre>