LIMIT is a row-limiting clause that tells the database to return only a specified number of rows from the query result set. It is evaluated after WHERE, GROUP BY, HAVING, and ORDER BY. When combined with OFFSET, it enables efficient keyset or page-based pagination. LIMIT is not part of the ANSI SQL-92 standard but is implemented by many popular databases, most notably PostgreSQL and MySQL. Because the clause executes after ORDER BY, omitting an ORDER BY can lead to non-deterministic result orders. Negative or NULL values are treated as zero and return no rows. LIMIT does not shorten query execution time if the database must still scan the full dataset to produce the result set; proper indexes and predicates are required for performance.
limit_count
(integer) - number of rows to return.offset_count
(integer) - number of rows to skip before starting to return rows. Optional.OFFSET, FETCH FIRST, TOP, ORDER BY, ROW_NUMBER
MySQL 3.23 (1998) and PostgreSQL 7.0 (2000)
LIMIT restricts how many rows the database sends back, returning at most the specified number.
Yes. LIMIT alone returns the first n rows. Add OFFSET when you need to skip a certain number of rows.
Only if you include an ORDER BY clause. Without ORDER BY, the row order is undefined and may change between executions.
OFFSET equals (page_number - 1) multiplied by page_size. For example, page 3 with 20 rows per page uses OFFSET 40.