PostgreSQL Select Top Syntax

The "select top" syntax is a syntax used by certain databases to limit the returned rows to the first N rows of a query.

Postgres does have a way to select the top N rows from an SQL query, but the syntax does not use the top keyword. Instead, the limit keyword must be used.

For example, databases that support the top syntax may use the following syntax to return the first 10 rows from a query:

select top 10 * from sales

The PostgreSQL equivalent of the above syntax would be the following:

select * from sales limit 10

PostgreSQL also gives the ability to limit the number of rows with an offset from the first row. That can be achieved using the limit N offset Y syntax.