title: MySQL LEFT JOIN using MAX & GROUP BY on joined table?
body: <p>I've got two tables (members and activities) and I'm trying to query the members with the latest activity for each member.  I've got it working with two queries (one to get the members and a second with a max(id) and group by(member) on the activities) and some code to merge the data.  I'm SURE it can be done with a single query, but I can't quite work it out.  Any ideas?</p>
  
  <p>members table</p>
  
  <pre><code>id, name
   1, Shawn
   2, bob
   3, tom
  </code></pre>
  
  <p>activities table</p>
  
  <pre><code>id, member_id, code, timestamp, description
   1,         1,  123,     15000, baked a cake
   2,         1,  456,     20000, ate dinner
   3,         2,  789,     21000, drove home
   4,         1,  012,     22000, ate dessert
  </code></pre>
  
  <p>desired result:</p>
  
  <pre><code>id, name,  activity_code, activity_timestamp, activity_description
   1, shawn, 012,           22000,              ate dessert
   2, bob,   789,           21000,              drove home
   3, tom,   null,          null,               null
  </code></pre>