SQLPathLab
Basic Query · Basic

LIMIT

Limits how many rows a query returns.

Overview

LIMIT caps the number of returned rows and is commonly used for previews and pagination. Pair it with ORDER BY so the meaning of the first rows is deterministic. Pagination syntax differs across databases, and deep OFFSET pagination can become expensive on large data sets.

Basic syntax

SELECT id, name, amount FROM orders ORDER BY id LIMIT 2;

Examples

LIMIT example

Order rows by id for a stable sequence and return only the first two orders.

Sample table

Table:orders
orders
idnameamount
1 Alice 1200
2 Bob 900
3 Cindy 1500
4 David 700

Run result

result
idnameamount
1 Alice 1200
2 Bob 900

Common issues

Which ten rows does LIMIT 10 return?

Only an ORDER BY clause gives the selected ten rows a defined and stable meaning.

Can LIMIT be used for pagination?

Yes, often with OFFSET in MySQL, although deep offsets can become slow.

Is LIMIT portable across databases?

Not completely. PostgreSQL and MySQL support LIMIT, while SQL Server commonly uses TOP or OFFSET/FETCH.

Tags

CommonFiltering

Was this explanation clear?