title: Mysql select max and sort date
body: <p>'tbl'</p>
  
  <p>| &nbsp; &nbsp; user &nbsp; &nbsp;| &nbsp; code &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; date  &nbsp; &nbsp; &nbsp;  &nbsp;| <br />
  | &nbsp; user 1 &nbsp; | &nbsp; 8549 &nbsp; | &nbsp; 2016-02-01 &nbsp; |<br />
  | &nbsp; user 2 &nbsp; | &nbsp; 7844 &nbsp; | &nbsp; 2016-02-17 &nbsp; |<br />
  | &nbsp; user 1 &nbsp; | &nbsp; 8675 &nbsp; | &nbsp; 2016-02-16 &nbsp; |<br />
  | &nbsp; user 3 &nbsp; | &nbsp; 2345 &nbsp; | &nbsp; 2016-02-21 &nbsp; |<br />
  | &nbsp; user 2 &nbsp; | &nbsp; 8545 &nbsp; | &nbsp; 2016-02-08 &nbsp; |<br /></p>
  
  <p>I have this set of records 'tbl' and i query to get the distinct user with it's latest date</p>
  
  <pre><code>SELECT user, code, max(date) as dt from tbl GROUP BY user
  </code></pre>
  
  <p>it returns:</p>
  
  <p>| &nbsp; &nbsp; user &nbsp; &nbsp;| &nbsp; code &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; date  &nbsp; &nbsp; &nbsp;  &nbsp;| <br />
  | &nbsp; user 1 &nbsp; | &nbsp; 8675 &nbsp; | &nbsp; 2016-02-16 &nbsp; |<br />
  | &nbsp; user 2 &nbsp; | &nbsp; 7844 &nbsp; | &nbsp; 2016-02-17 &nbsp; |<br />
  | &nbsp; user 3 &nbsp; | &nbsp; 2345 &nbsp; | &nbsp; 2016-02-16 &nbsp; |<br /></p>
  
  <p>my problem is that i have no idea how to sort the date to desc.
  I want a result like this:</p>
  
  <p>| &nbsp; &nbsp; user &nbsp; &nbsp;| &nbsp; code &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; date  &nbsp; &nbsp; &nbsp;  &nbsp;| <br />
  | &nbsp; user 1 &nbsp; | &nbsp; 8675 &nbsp; | &nbsp; 2016-02-16 &nbsp; |<br />
  | &nbsp; user 3 &nbsp; | &nbsp; 2345 &nbsp; | &nbsp; 2016-02-16 &nbsp; |<br />
  | &nbsp; user 2 &nbsp; | &nbsp; 7844 &nbsp; | &nbsp; 2016-02-17 &nbsp; |<br /></p>
  
  <p>Thanks :)</p>