title: Retrieve last 2 records where grouping by column
body: <p>I have a mysql query to select the most recent record for each grouped using the below query</p>
  <pre><code>SELECT *
  FROM tbl_prices
  WHERE id IN (
      SELECT MAX(id)
      FROM tbl_prices
      GROUP BY instrument
  );
  </code></pre>
  <p>but now I need to get the most recent 2 records for each grouped column. The reason being I need to compare the difference between the latest 2 records to perform additional functionality on the result.</p>
  <p>Should I create 2 queries to get the results and if so how would I get the most recent - 1</p>
  <p>I've had a look at this SO post (<a href="https://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group-mysql">Retrieving the last record in each group - MySQL</a>) but it doesn't seem to fit my requirements as it's still only the latest record for each group.</p>