Tsallaka zuwa abun ciki
Justice Tech School

LIMIT (and TOP)

LIMIT returns only the first few rows, usually together with ORDER BY. OFFSET skips rows, which is how pages of results work.

Example
SELECT name, score
FROM students
ORDER BY score DESC
LIMIT 3;

Result

name   | score
Ada    | 92
Zainab | 88
Amina  | 85
Example
SELECT name
FROM students
ORDER BY id
LIMIT 3 OFFSET 3;

Result

name
Wanjiru
Tunde
Zainab
  • SQL Server and MS Access use SELECT TOP 3 ... instead of LIMIT. Oracle 12c and newer uses FETCH FIRST 3 ROWS ONLY.

Exercise

Return only 2 rows.

SELECT * FROM students  2;

Quiz Test

What does LIMIT 3 do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.