How to Limit Query Results for PostgreSQL Databases

Many times users are only interested in either the first so many records returned from a query or a range of records returned from a query. PostgreSQL provides a mechanism for limiting query results using the limit and / or offset SQL syntax. Listed below are examples of SQL select queries using the limit and offset syntax. These include examples for returning the first N rows for a query, or a range of records from a query.

Example 1: Returning the first 100 rows from a table called employee:

select * from employee limit 100

Example 2: Returning 10 records from the table employee starting at row 5

select * from employee limit 10 offset 5

Many other databases also support limiting rows returned from queries. Listed below are links that show how to limit rows for other popular databases: