title: MySQL select GROUP BY order
body: <p>I have a mysql statement</p>
  
  <pre><code>SELECT * 
  FROM tbl_messages 
  WHERE to_user_id = '$user_id' OR from_user_id = '$user_id' 
  GROUP BY from_user_id 
  ORDER BY date_sent DESC
  </code></pre>
  
  <p>and it is producing the correct results however they are not in the correct order.</p>
  
  <p>The grouping works well but it record displayed in the group is the first recorded entered into the DB but I would like the latest record to be displayed in each group.</p>
  
  <p>Is there a way to have the latest record displayed for each group?</p>
  
  <pre><code>2011-12-19 12:16:25 This is the first message
  2011-12-19 12:18:20 This is the second message
  2011-12-19 12:43:04 This is the third message
  </code></pre>
  
  <p>The group shows 'This is the first message' where I would like 'This is the third message' as that is the most recent record/message.</p>
  
  <p>Cheers</p>