title: How to select multiple columns from a table while ensuring that one specific column doesn't contain duplicate values in sql server?
body: <p><strong>Table:</strong><br/></p>
  
  <pre><code>x_id---y---z_id------a-------b-------c
  1------0----NULL----Blah----Blah---Blah
  2------0----NULL----Blah----Blah---Blah
  3------10---6-------Blah----Blah---Blah
  3------10---5-------Blah----Blah---Blah
  3------10---4-------Blah----Blah---Blah
  3------10---3-------Blah----Blah---Blah
  3------10---2-------Blah----Blah---Blah
  3------10---1-------Blah----Blah---Blah
  4------0----NULL----Blah----Blah---Blah
  5------0----NULL----Blah----Blah---Blah
  </code></pre>
  
  <p><strong>My Query</strong>:</p>
  
  <pre><code>SELECT
      #temp.x_id,
      #temp.y,
      MAX(#temp.z_id) AS z_id
  FROM #temp
  GROUP BY 
      #temp.x_id
  </code></pre>
  
  <p><strong>Error</strong>:
  <code>Column 'y' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</code></p>
  
  <p><strong>Requirement:</strong>
  I want x_id to be unique and i want to select the MAX value of z_id</p>
  
  <p><strong>Expected Output:</strong><br/></p>
  
  <pre><code>x_id---y---z_id------a-------b-------c
  1------0----NULL---Blah----Blah-----Blah
  2------0----NULL---Blah----Blah-----Blah
  3------10---6------Blah----Blah-----Blah
  4------0----NULL---Blah----Blah-----Blah
  5------0----NULL---Blah----Blah-----Blah
  </code></pre>