title: How to get the most recent records from MySQL?
body: <p>I have a table that stores some reports about an url and they have a field like created_date. The same report can be generated (and stored) multiple times because the values can change. How can I get the url reports, but just the most recent ones?</p>
  
  <p>My table (page_report):</p>
  
  <pre><code>id INT PK
  url VARCHAR(255)
  created_date TIMESTAMP
  </code></pre>
  
  <p>Sample data:</p>
  
  <pre><code>id    url          created_date
  1     google.com   2016-11-01
  2     google.com   2016-11-05
  3     bing.com     2016-11-03
  4     bing.com     2016-11-06
  </code></pre>
  
  <p>I need:</p>
  
  <pre><code>id    url          created_date
  1     google.com   2016-11-05
  2     bing.com     2016-11-06
  </code></pre>
  
  <p>What I have so far:</p>
  
  <pre><code>SELECT r1.*
  FROM page_report r1
  LEFT JOIN page_report r2 ON r1.url = r2.url AND r1.created_date &lt; r2.created_date
  WHERE r2.url IS NULL;
  </code></pre>
  
  <p>But it's very slow. Is there any better way?</p>
  
  <p>Hope I made myself clear and thanks in advance!</p>