title: Get unique values using STRING_AGG in SQL Server
body: <p>The following query returns the results shown below:</p>
  
  <pre><code>SELECT 
      ProjectID, newID.value
  FROM 
      [dbo].[Data] WITH(NOLOCK)  
  CROSS APPLY 
      STRING_SPLIT([bID],';') AS newID  
  WHERE 
      newID.value IN ('O95833', 'Q96NY7-2') 
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>ProjectID   value
  ---------------------
  2           Q96NY7-2
  2           O95833
  2           O95833
  2           Q96NY7-2
  2           O95833
  2           Q96NY7-2
  4           Q96NY7-2
  4           Q96NY7-2
  </code></pre>
  
  <p>Using the newly added <code>STRING_AGG</code> function (in SQL Server 2017) as it is shown in the following query I am able to get the result-set below.</p>
  
  <pre><code>SELECT 
      ProjectID,
      STRING_AGG( newID.value, ',') WITHIN GROUP (ORDER BY newID.value) AS 
  NewField
  FROM
      [dbo].[Data] WITH(NOLOCK)  
  CROSS APPLY 
      STRING_SPLIT([bID],';') AS newID  
  WHERE 
      newID.value IN ('O95833', 'Q96NY7-2')  
  GROUP BY 
      ProjectID
  ORDER BY 
      ProjectID
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>ProjectID   NewField
  -------------------------------------------------------------
  2           O95833,O95833,O95833,Q96NY7-2,Q96NY7-2,Q96NY7-2
  4           Q96NY7-2,Q96NY7-2
  </code></pre>
  
  <p>I would like my final output to have only unique elements as below:</p>
  
  <pre><code>ProjectID   NewField
  -------------------------------
  2           O95833, Q96NY7-2
  4           Q96NY7-2
  </code></pre>
  
  <p>Any suggestions about how to get this result? Please feel free to refine/redesign from scratch my query if needed.</p>