← SQL basics
Lesson 2 of 4
Sorting and limits
Watch, read the card, then practise. Sorting · Top results
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicSorting
ORDER BY sorts the result by one or more columns.
Remember: If the order matters, always write ORDER BY.
Top results
LIMIT keeps only the first few rows, often after sorting, to get the top results.
Remember: Top N = ORDER BY ... DESC, then LIMIT N.
Try the example in Code Lab
SELECT name, marks FROM students ORDER BY marks DESC;