LIMIT
A clause that returns at most a given number of rows, optionally after skipping a number of rows with OFFSET.
In more detail
LIMIT is what SQLite, MySQL and PostgreSQL all accept; the SQL standard spelling is fetch first n rows only, which PostgreSQL supports and SQLite does not. Without ORDER BY, which rows you get is not defined. OFFSET still reads and discards the skipped rows.
Example
SELECT id, name FROM products ORDER BY id LIMIT 3 OFFSET 3;Related terms
- ORDER BY — The clause that sorts a query's answer by one or more columns, each ascending or descending.
- offset pagination — Paging by saying how many items to skip, such as ?limit=2&offset=4.
- keyset pagination — Paging by remembering the last key the reader saw and asking for rows after it, which does not drift.
Taught in
- The SELECT Statement And Projection — PostgreSQL, Indexing & Relational Data Modeling
- Ordering And Limiting Results — PostgreSQL, Indexing & Relational Data Modeling
- Where PostgreSQL Differs From SQLite — PostgreSQL, Indexing & Relational Data Modeling