title: Get first/last n records per group by
body: <p>I have two tables : <code>tableA (idA, titleA)</code> and <code>tableB (idB, idA, textB)</code> with a one to many relationship between them. For each row in tableA, I want to retrieve the last 5 rows corresponding in tableB (ordered by idB). </p>
  
  <p>I've tried</p>
  
  <pre><code>SELECT * FROM tableA INNER JOIN tableB ON tableA.idA = tableB.idA LIMIT 5
  </code></pre>
  
  <p>but it's just limiting the global result of INNER JOIN whereas I want to limit the result for each different tableA.id</p>
  
  <p>How can I do that ?</p>
  
  <p>Thanks</p>