sql · level 1 · unit 3 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
shows only the first few rows.
Some tables have thousands of rows, and you want only a handful. LIMIT 3 at the very end of a query stops the result after three rows.
On its own, LIMIT gives you whichever rows come first. Put ORDER BY in front and it becomes a top three: sort biggest first, then keep three.
The parts of a query always go in this order: SELECT, FROM, WHERE, ORDER BY, then LIMIT, last of all.
SELECT player, points FROM scores ORDER BY points DESC LIMIT 3; Ask for more rows than there are and you get every row, with no error.
guess first
Sorted, then trimmed. Which snack comes back?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT name, price FROM snacks ORDER BY price LIMIT 1;
your turn
Your turn. Make a list of the newest films.
Choose how many films make your list. The query sorts them by year, newest first, then keeps that many.
result
Your answer appears here as a table.
fix it
LIMIT has jumped the queue. Can you fix it?
result
Your answer appears here as a table.
- Read the error. It points near
ORDER. What comes right before it? LIMITmust always be the very last part of a query.- Move LIMIT 2 to the end, after DESC, then press run.
nailed it
you made your first top list. :D
LIMITkeeps only the first few rows.ORDER BYplusLIMITmakes a top list.LIMITalways goes last.
new words in your collection
- LIMIT
This lesson isn’t saved. A free account remembers every lesson you finish.