title: how can i find second maximum of my query
body: <p>Here is my SQL query to find a row in <code>currency_price</code> table grouped by maximum date of inserting to table. My question is how to find the <strong>second maximum</strong>. I mean how can I change this query to find the <em>second maximum row in each group</em>: </p>
  
  <pre><code>select currency_id,buy,sell 
  from (select * from currency_price  order by `currency_id`, cu_date desc,buy,sell) x 
  group by `currency_id`
  </code></pre>
  
  <p>with this query i found a row for each id so for example i have sell and buy for each id .exm: </p>
  
  <pre><code>id    sell buy
  1000  500  480
  1001  20   19
  ...
  </code></pre>
  
  <p>but here i want the second maximum date for each id.</p>
  
  <p>I know some query to find second maximum but all does not take me to my answer.</p>