title: SQL How to display all records in group by
body: <p>I have a table structure like this:</p>
  
  <pre><code>UserID  | Firstname | LastName | DateTime
  -------------------------------------------
  1       | John      | Doe      | 2015-04-27
  2       | Karl      | Watts    | 2015-04-26
  1       | John      | Doe      | 2015-04-25
  3       | Jane      | Howard   | 2015-04-28
  </code></pre>
  
  <p>Is there a way I can write a query to get the data ordered by DateTime but grouped by UserID? I want the record with the most recent DateTime at the top and the remainder of that users records to follow. Then it should be the next user with the most recent date, followed by all of their records. Like this:</p>
  
  <pre><code>UserID  | Firstname | LastName | DateTime
  -------------------------------------------
  3       | Jane      | Howard   | 2015-04-28
  1       | John      | Doe      | 2015-04-27
  1       | John      | Doe      | 2015-04-25
  2       | Karl      | Watts    | 2015-04-26
  </code></pre>
  
  <p>I just don't know if this is possible with a single query. So far I've come up with this query:</p>
  
  <pre><code>SELECT UserID, FirstName, LastName, MAX(DateTime) as MaxDateTime
  FROM Table
  GROUP BY UserID, FirstName, LastName
  ORDER BY MaxDateTime DESC
  </code></pre>
  
  <p>Which gives me the most recent records in the correct order, but I dont know how to include the remainder of the records for each user. I'm thinking I need to use a join but when I do, the group by groups everything together (as it should). </p>
  
  <p>EDIT: </p>
  
  <ol>
  <li>Yes, it needs normalization.</li>
  <li>It's SQL Server 2008 R2, I confirmed OVER works with 2008 and later so that's perfect.</li>
  <li>In case of tie, lower UserID first works.</li>
  </ol>