title: SELECT set of most recent id, amount FROM table, where id occurs many times
body: <p>I have a table recording the amount of data transferred by a given service on a given date. One record is entered daily for a given service.</p>
  
  <p>I'd like to be able to retrieve the most recent <code>amount</code> for a set of services.</p>
  
  <p>Example data set:</p>
  
  <pre><code>serviceId | amount | date
  -------------------------------
  1         | 8      | 2010-04-12   
  2         | 11     | 2010-04-12  
  2         | 14     | 2010-04-11  
  3         | 9      | 2010-04-11  
  1         | 6      | 2010-04-10  
  2         | 5      | 2010-04-10  
  3         | 22     | 2010-04-10  
  4         | 17     | 2010-04-19
  </code></pre>
  
  <p>Desired response (service ids 1,2,3):</p>
  
  <pre><code>serviceId | amount | date
  -------------------------------
  1         | 8      | 2010-04-12   
  2         | 11     | 2010-04-12  
  3         | 9      | 2010-04-11 
  </code></pre>
  
  <p>Desired response (service ids 2, 4):</p>
  
  <pre><code>serviceId | amount | date
  -------------------------------
  2         | 11     | 2010-04-12  
  4         | 17     | 2010-04-19
  </code></pre>
  
  <p>This retrieves the equivalent as running the following once per serviceId:</p>
  
  <pre><code>SELECT serviceId, amount, date
  FROM table
  WHERE serviceId = &lt;given serviceId&gt;
  ORDER BY date DESC
  LIMIT 0,1
  </code></pre>
  
  <p>I understand how I can retrieve the data I want in X queries. I'm interested to see how I can retrieve the same data using either a single query or at the very least less than X queries.</p>
  
  <p>I'm very interested to see what might be the most efficient approach. The table currently contains 28809 records.</p>
  
  <p>I appreciate that there are other questions that cover selecting the most recent set of records. I have examined three such questions but have been unable to apply the solutions to my problem.</p>