Students combine two tables with JOIN ... ON and then filter or group the joined rows.
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 9 min · Investigate 7 min · Modify and Make 14 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.
Give pairs a printed list of songs and a list of artists. They draw a line from each song to its artist's country, then run the join to check.
Picturing what the join does. Use two paper lists and draw lines between the matching rows.
| What you will see | A question to ask | The fix |
|---|---|---|
| ambiguous column name | Which table does that column belong to? | Put the table name and a dot in front of it. |
| Far too many rows. | Does the join have an ON line? | Add ON so each song is only paired with its own artist. |
| A song is missing from the result. | Does its artist appear in the artists table, spelled the same? | A join only keeps rows that match. Check the spelling in both tables. |
One possible solution for each task. Other correct programs are fine.
SELECT songs.title, artists.country
FROM songs
JOIN artists ON songs.artist = artists.name;
SELECT artists.country, COUNT(*)
FROM songs
JOIN artists ON songs.artist = artists.name
GROUP BY artists.country;
Stretch: Show each song with the artist's formed year, newest bands first.
Support: Give the whole JOIN line and ask students to choose the columns.
Why keep artists in their own table instead of a country column in songs?
A country is stored once for each artist, so a mistake is fixed in one place and nothing is repeated.
Next lesson: change the data itself with INSERT, UPDATE and DELETE.