title: MySQL: Order by max date of a joined table
body: <p>I have two tables - <code>groups</code> and <code>messages</code>. </p>
  
  <hr>
  
  <p>Messages has the following fields <code>group_id</code> and <code>date_created</code>. So a lot of messages can be added to a single group. I want to select all groups from table - most relevant on top, i.e. order by latest message date. I've tried something like this</p>
  
  <pre><code>SELECT g.*, MAX(m.date_created) AS mdt FROM groups g
  LEFT JOIN messages m ON g.id = m.group_id
  ORDER BY mdt DESC;
  </code></pre>
  
  <p>But this query returns only one row and max message date from the whole table.</p>