SQL TRAINING · LESSON 4 OF 4 · 3 MIN READ
Take the top results with LIMIT
Sort the intended result before selecting a small subset.
Understand the idea
LIMIT restricts the number of returned rows. A limit by itself does not mean highest, newest or best: it just takes rows from the result order. To request top scores, specify the relevant descending order and then limit how many rows are returned.
Work through it
Build the query in small steps: select the columns, identify the table, apply a filter if needed, set the sort and set the limit. Re-read the requested row count and check whether ties require a rule. The exercise uses exactly three rows and a no-ties test dataset.
SEE IT IN CONTEXT
Worked example
SELECT name, score FROM students ORDER BY score DESC LIMIT 3;
The query sorts scores from largest to smallest and returns three rows. In this practice table, this produces the requested top three. Database dialects can differ, so check the documentation for the system you use.
Common mistakes to avoid
- Using LIMIT without the necessary sort.
- Keeping four rows when three are requested.
- Assuming every database supports identical syntax.
NOW HAVE A GO
Find the three highest quiz scores
Apply the idea in the linked activity. Follow its own brief and values; examples in this lesson are illustrative.
Try the practice activity →Download the practice starterAbout the linked activity
DigiSkill has two SQL practice activities and a focused browser checker: SELECT name, score FROM students, numeric WHERE comparisons, ORDER BY score ASC/DESC and LIMIT. Lessons build toward those two activities. No live database, JOIN, GROUP BY or writes are included.
Reading marks are self-reported and saved only in this browser.
0 of 4 lessons marked as read
Keep learning: Reference documentation ↗
