title: SQL Select Distinct Values, but order by a different value
body: <p>I want to select all distinct order_ids from my table, and order that list by the date column. Using DISTINCT is of course a query-wide parameter, so trying something like this doesn't work:</p>
  
  <pre><code>SELECT DISTINCT(orderId, datetime) 
  FROM table 
  ORDER BY datetime DESC
  </code></pre>
  
  <p>This returns all DISTINCT combinations of the orderId and datetime, so I'm left with multiple orderIds, which I don't want. Therefore I'm thinking that the DISTINCT clause is not the way to go. Does anyone have any suggestions on how I could solve this problem?</p>
  
  <p>Thanks!</p>