AtomLearnAtomLearn
DashboardGoalsPathAchievementsReviewSign In
DashboardSQL & DatabasesLimiting Results with LIMIT
SQL & DatabasesNot Started

Limiting Results with LIMIT

Cap the number of rows returned with LIMIT (and paginate with OFFSET)

0%
Knowledge0%
Learn & Drill
Fluency0%
Drill & Speed
Retention0%
Mastery & Review
Confidence0%
All modes
Practice

Free tier: read the explanation here. Upgrade to Pro for Drills, Speed challenges & Mastery badges.

Upgrade
Knowledge
Fluency
Retention

Knowledge Debt detected

You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.

Explanation

LIMIT caps how many rows a query returns.

sql
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 5;

The "top N" pattern: ORDER BY + LIMIT together find the highest/lowest N rows — e.g. the 5 highest-paid employees.

Pagination with OFFSET — skip the first N rows, then return the next page: ``sql SELECT name FROM employees ORDER BY name LIMIT 10 OFFSET 20; -- rows 21-30 ("page 3" of 10)

Full clause order so far:

sql SELECT columns FROM table WHERE condition ORDER BY column LIMIT n;

Examples

Top 5 highest-paid engineers

WHERE filters to Engineering, ORDER BY sorts highest-first, LIMIT keeps only the top 5

SELECT name, salary
FROM employees
WHERE department = 'Engineering'
ORDER BY salary DESC
LIMIT 5;

How well did you understand this?

Next in SQL & Databases

Removing Duplicates with DISTINCT

Continue