title: mysql how to display last 2 records for each customer
body: <p>I want to display last 2 records for each customer based on date, 
  eg:<br/></p>
  
  <pre><code>      id   |   name   |   date
         1   |    a     |  2015-10-11
         2   |    a     |  2015-09-11
         3   |    b     |  2015-10-10
         4   |    b     |  2015-09-01
  </code></pre>
  
  <p>I tried like </p>
  
  <blockquote>
    <p>SELECT id,cust_id FROM ( SELECT id,cust_id @currcount := IF(@currvalue
    = cust_id, @currcount + 1, 1) AS cnt    FROM customer   ORDER BY id DESC) AS whatever WHERE cnt &lt;= 2</p>
  </blockquote>
  
  <p>but it displays all records</p>