Skip to content
Advertisement

Grouped LIMIT in PostgreSQL: show the first N rows for each group?

I need to take the first N rows for each group, ordered by custom column.

Given the following table:

I need the first 2 rows (ordered by name) for each section_id, i.e. a result similar to:

I am using PostgreSQL 8.3.5.

Advertisement

Answer

New solution (PostgreSQL 8.4)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement