🎯 LIMIT and OFFSET in SQL

Last Updated: January 2026


The LIMIT and OFFSET clauses are used to control how many rows are returned in a query result. They are especially useful for pagination and large datasets.

LIMIT

  • LIMIT restricts the maximum number of rows returned
  • It does not change the data, only the output

Hinglish Tip 🗣: LIMIT batata hai — kitni rows tak result chahiye.


Syntax of LIMIT

SELECT column_name
FROM table_name
LIMIT number;

Example

SELECT *
FROM students
LIMIT 5;
  • Returns only first 5 rows

OFFSET?

  • OFFSET specifies how many rows to skip before starting to return data
  • Commonly used with LIMIT

Hinglish Tip 🗣: OFFSET ka matlab hai — pehle ki rows skip karna.


Syntax of LIMIT with OFFSET

SELECT column_name
FROM table_name
LIMIT limit_value OFFSET offset_value;

Example: LIMIT with OFFSET

SELECT *
FROM students
LIMIT 5 OFFSET 10;

Meaning:

  • Skip first 10 rows
  • Then return next 5 rows

📚 Pagination Example

Assume:

  • Page size = 10

Page 1

LIMIT 10 OFFSET 0

Page 2

LIMIT 10 OFFSET 10

Page 3

LIMIT 10 OFFSET 20

🔁 LIMIT with ORDER BY

LIMIT without ORDER BY can return unpredictable results.

SELECT *
FROM students
ORDER BY marks DESC
LIMIT 3;

✔ Returns top 3 students by marks

SELECT *
FROM students
ORDER BY marks DESC
LIMIT 1 OFFSET 1;

✔ Returns second student by marks