title: Selecting non-group field from query with aggregate function
body: <p>I have a table <code>tbl</code> with three columns:</p>
  
  <pre><code>id | fk | dateof
   1 |  1 | 2012-01-01
   2 |  1 | 2012-01-02
   3 |  2 | 2012-02-01
   4 |  2 | 2012-03-01
   5 |  3 | 2012-04-01
  </code></pre>
  
  <p><code>id</code> is the ID of the row, <code>fk</code> is a foreign key to another table and <code>dateof</code> is a date column.</p>
  
  <p>What I want is to get the <code>id</code> where the <code>dateof</code> is the latest grouped by <code>fk</code>. What I've tried:</p>
  
  <pre><code>SELECT id, MAX(dateof) FROM tbl GROUP BY fk
  </code></pre>
  
  <p>But I get results like this:</p>
  
  <pre><code>1 | 2012-01-02
  3 | 2012-03-01
  5 | 2012-04-01
  </code></pre>
  
  <p>When I want:</p>
  
  <pre><code>2 | 2012-01-02
  4 | 2012-03-01
  5 | 2012-04-01
  </code></pre>
  
  <p>How can I query and get the results I'm looking for? MySQL server if it matters. Thanks.</p>