MySQL + SQL · Lesson 51
LIMIT and OFFSET in MySQL
LIMIT — Restrict Rows
SELECT * FROM students ORDER BY marks DESC LIMIT 3;Returns only the top 3 students by marks.
OFFSET — Skip Rows
SELECT * FROM students LIMIT 5 OFFSET 10;
-- same as
SELECT * FROM students LIMIT 10, 5;Skips 10 rows, then returns 5 — used for pagination (page 3 of results).
Summary
- LIMIT n = return at most n rows.
- OFFSET skips rows; together they power pagination.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.