Using the LIMIT clause

The LIMIT clause is used to retrieve a number of rows from a larger data set. It helps fetch the top n records. The LIMIT and OFFSET clauses allow you to retrieve just a portion of the rows that are generated by the rest of the query from a result set:

SELECT select_list
FROM table_expression
[LIMIT { number | ALL }] [OFFSET number]

If a limit count is given, no more than that many rows will be returned (but possibly fewer, if the query itself yields fewer rows). LIMIT ALL is the same as omitting the LIMIT clause.

The OFFSET clause suggests skipping many rows before beginning to return rows. OFFSET 0 is the same as omitting the OFFSET clause. If both OFFSET and LIMIT appear, then the OFFSET rows will be skipped before starting ...

Get PostgreSQL Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.