title: How to select last record from each day with MySQL
body: <p>I know there are already some solutions to this question but they don't seem to be working for me.</p>
  
  <p>I want to select the last record from each day, per user, on my database. I have a database that stores a user's location by country and date down to the second.</p>
  
  <p>The select query I'm trying to run is:</p>
  
  <pre><code>SELECT MAX(date), id, country FROM dk_location_records WHERE userid = '10'
  AND (date &gt; '2012-04-06 00:00:00' AND date &lt; '2012-05-08 23:59:59')
  AND active = '1' GROUP BY DATE(date) ORDER BY date ASC
  </code></pre>
  
  <p>However, what this actually does is show me the last date from each day, but not the correctly corresponding <code>id</code> and <code>country</code>. It actually gets the first <code>id</code> and <code>country</code>, alongside the last <code>date</code>.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Help greatly appreciated!</p>
  
  <p>Thanks,</p>
  
  <p>Jack</p>