Home / SQL / Reference / Querying

SQL LIMIT and OFFSET

Return only the first n rows (after skipping m).

Syntax

SELECT … ORDER BY … LIMIT n [OFFSET m];

With ORDER BY this gives "top n" queries and paging. LIMIT runs last, after sorting.

Example

Query (on the shop database used in the SQL course)

SELECT name, price
FROM products
ORDER BY price DESC
LIMIT 3;

Result

nameprice
Standing desk549.0
Ergonomic chair399.0
27-inch monitor329.0

3 rows

Good to know. SQL Server uses SELECT TOP 3; standard SQL is FETCH FIRST 3 ROWS ONLY.

Related

Learn it step by step in the free lesson SELECT: Choosing Columns, with exercises that check your queries.