title: Getting 5 results per item - Postgres
body: <p>So I have a list of causes and a list of matches (an object that holds two foreign keys), and for each causes that fits some condition, I want to get the first five matches to that cause. However I'm having trouble doing it.</p>
  
  <p>I started with this code, selecting all matches for the selected causes</p>
  
  <pre><code>SELECT * FROM matches m
  WHERE m.cause_id in (
      SELECT cz.id
          FROM causes cz
          WHERE (*condition*)
  </code></pre>
  
  <p>Then tried joins so I could limit it, but I haven't been able to find how to.</p>
  
  <pre><code>SELECT * FROM matches m
  WHERE (*condition*)
  JOIN causes cz ON m.cause_id = cz.id
  
  ????
  </code></pre>
  
  <p>'Limit' limits the total number of end results, and I can't limit the number of causes matched either. Suggestions?</p>