title: How to get the latest record in each group using GROUP BY?
body: <p>Let's say I have a table called <code>messages</code> with the columns:</p>
  
  <pre><code>id | from_id | to_id | subject | message | timestamp
  </code></pre>
  
  <p>I want to get the latest message from each user only, like you would see in your FaceBook inbox before you drill down into the actual thread.</p>
  
  <p>This query seems to get me close to the result I need:</p>
  
  <pre><code>SELECT * FROM messages GROUP BY from_id
  </code></pre>
  
  <p>However the query is giving me the oldest message from each user and not the newest.</p>
  
  <p>I can't figure this one out. </p>