title: Grouped LIMIT in PostgreSQL: show the first N rows for each group?
body: <p>I need to take the first N rows for each group, ordered by custom column.</p>
  
  <p>Given the following table:</p>
  
  <pre><code>db=# SELECT * FROM xxx;
   id | section_id | name
  ----+------------+------
    1 |          1 | A
    2 |          1 | B
    3 |          1 | C
    4 |          1 | D
    5 |          2 | E
    6 |          2 | F
    7 |          3 | G
    8 |          2 | H
  (8 rows)
  </code></pre>
  
  <p>I need the first 2 rows (ordered by <b>name</b>) for each <b>section_id</b>, i.e. a result similar to:</p>
  
  <pre><code> id | section_id | name
  ----+------------+------
    1 |          1 | A
    2 |          1 | B
    5 |          2 | E
    6 |          2 | F
    7 |          3 | G
  (5 rows)
  </code></pre>
  
  <p>I am using PostgreSQL 8.3.5.</p>