title: Group By: What if I don't want to perform an aggregate function on a column?
body: <p>I have a table, Students, with the following columns:</p>
  
  <pre><code>________________________________________________
  | id   |  name  |  class  |  date_registrered  | 
  ------------------------------------------------
  </code></pre>
  
  <p>I want to select one row for every unique class, and only the row with the largest value in date_registrered,
  i.e. I want to select the latest registrered Student for every class, including all the data for that one.</p>
  
  <p>I tried:</p>
  
  <pre><code>SELECT id, name, class, MAX(date_registrered)
  FROM Students
  GROUP BY class;
  </code></pre>
  
  <p>I get the following error: </p>
  
  <blockquote>
    <p>Column 'Students.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/13999817/reason-for-column-is-invalid-in-the-select-list-because-it-is-not-contained-in-e">This question on SO</a> adresses a simplified version of this issue. However, the example is for 2 columns only.</p>
  
  <p>I only want to group by class, and I only want to perform an aggregate function on date_registrered. I also want to display all the other columns for the row with the max date_registrered for every class.</p>
  
  <p>Do you know how to fix it?</p>