BeginnerCoder

Lesson 6 — ORDER BY & LIMIT

LIMIT and OFFSET: top-N and pages

LIMIT n returns only the first n rows of the result. Combined with ORDER BY it answers "top 3" questions. OFFSET k skips the first k rows — that is how websites show pages of results: page 2 with 3 items per page is LIMIT 3 OFFSET 3.

SELECT name FROM players ORDER BY score DESC LIMIT 3

Watch out: LIMIT without ORDER BY gives you "some" rows, not the best ones.

Why it matters: leaderboards and paginated lists (search results, product pages) are built with exactly this.

Want it another way?
Task

Write the page-2 query: top scores first, 3 per page, skipping the first 3. Expected: Kai, Lee, Mo.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.