Students sort with ORDER BY, reverse with DESC, keep the top rows with LIMIT, and combine it with WHERE.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 6 min · Modify and Make 11 min
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Pairs invent a top-three question about the songs, swap, and write the query for each other's question.
The fixed order of the parts. Read the query aloud as a sentence.
| What you will see | A question to ask | The fix |
|---|---|---|
| syntax error near ORDER | Which comes first, WHERE or ORDER BY? | The order is SELECT, FROM, WHERE, ORDER BY, LIMIT. |
| The wrong end of the list. | Does the order go smallest first or biggest first? | Add DESC for biggest first. |
One possible solution for each task. Other correct programs are fine.
SELECT title, seconds
FROM songs
ORDER BY seconds DESC
LIMIT 1;
SELECT title, plays
FROM songs
WHERE genre = 'rock'
ORDER BY plays DESC
LIMIT 3;
Stretch: Sort by two columns, such as genre and then plays DESC.
Support: Give the query with ORDER BY done and ask only for LIMIT.
What is the order of the parts of a query so far?
SELECT, FROM, WHERE, ORDER BY, LIMIT.
Next lesson: count and add up rows to one answer.