Optional extension: students keep playlists and songs in two flat tables linked by a shared value (each song's playlist field names its playlist). Clicking a playlist sets Chosen and copies the songs whose playlist = Chosen into a Shown table: a join, built with the filter pattern from lesson 5. The Check shows the link breaking when a name changes in one table only. Make it yours: add a song to the open playlist.
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.
Try 5 min · Build 1–2 20 min · Check 5 min · Make it yours 15 min
This is how relational databases keep data: flat tables, linked by a shared value, rather than tables inside tables. Real databases link by an id number that never changes; here the name does the job, which the Check shows is fragile.
The JSON view (the { } JSON button under each table) shows both tables as flat lists of records. Students who go on to Python or web will meet nested JSON, and building it from flat tables is a good exercise there.
The SQL course (code/sql) is the natural next step.
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.
Two flat tables, linked by a value they share: the way databases do it.
Rename Gym to Workout in Playlists only, then click it. Why are its songs gone? How could a database avoid this?
Link by an id number that never changes, not by a name.
Seeing that the link is just a value: open the JSON view of both tables side by side and point to the matching names.
| What you will see | A question to ask | The fix |
|---|---|---|
| No songs show. | What does each song's playlist field say, exactly? | The comparison is exact: Study and study are different. Check spelling and capitals in both tables. |
| Songs from the last playlist stay. | Where is Shown cleared? | Clear table Shown on the parent event, before the loop. |
One possible solution for each task. Other correct programs are fine.
{"version":1,"name":"Linked playlists","device":"web","features":{"level":4},"variables":[{"name":"Playlists","table":{"fields":[{"name":"name","type":"text"}]},"value":[{"name":"Study"},{"name":"Gym"},{"name":"Chill"}]},{"name":"Songs","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"playlist","type":"link","to":"Playlists"}]},"value":[{"title":"Blue Sky","artist":"Kai","playlist":"Study"},{"title":"Arc","artist":"Mo","playlist":"Gym"},{"title":"Cove","artist":"Lu","playlist":"Chill"},{"title":"Nova","artist":"Kai","playlist":"Study"},{"title":"Tidal","artist":"Rae","playlist":"Gym"},{"title":"Lanterns","artist":"Mo","playlist":"Study"}]},{"name":"Shown","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"playlist","type":"text"}]},"value":[]},{"name":"Chosen","value":""}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"Playlists","visible":true,"vars":{}}]},{"name":"PlaylistTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":70,"w":200,"h":200,"text":"","visible":true,"vars":{},"source":"Playlists","columns":""}]},{"name":"Heading","kind":"text","instanceVars":[],"instances":[{"id":"t1","x":250,"y":70,"w":520,"h":36,"text":"Click a playlist","visible":true,"vars":{}}]},{"name":"ShownTable","kind":"table","instanceVars":[],"instances":[{"id":"T2","x":250,"y":112,"w":520,"h":260,"text":"","visible":true,"vars":{},"source":"Shown","columns":"title, artist"}]},{"name":"AllLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":290,"w":200,"h":30,"text":"Every song is in Songs.","visible":true,"vars":{}}]},{"name":"TitleInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":250,"y":390,"w":200,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"ArtistInput","kind":"input","instanceVars":[],"instances":[{"id":"i2","x":462,"y":390,"w":150,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"AddButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":624,"y":388,"w":146,"h":46,"text":"Add to playlist","visible":true,"vars":{}}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onItemClicked","target":"PlaylistTable"}],"actions":[{"type":"setVar","var":"Chosen","value":"ClickedItem.name"},{"type":"tableClear","table":"Shown"}],"children":[{"id":"e1a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.playlist","op":"=","right":"Chosen"}],"actions":[{"type":"tableAdd","table":"Shown","values":{"title":"LoopItem.title","artist":"LoopItem.artist","playlist":"LoopItem.playlist"}}],"children":[]},{"id":"e1b","else":false,"conds":[],"actions":[{"type":"setText","target":"Heading","value":"Chosen & \" (\" & count(Shown) & \" songs)\""}],"children":[]}]},{"id":"e2","else":false,"conds":[{"type":"onClicked","target":"AddButton"}],"actions":[{"type":"tableAdd","table":"Songs","values":{"title":"TitleInput.text","artist":"ArtistInput.text","playlist":"Chosen"}}],"children":[]}]}]}
Open task: any program that does what the step asks.
Stretch: Add a Delete playlist button that also removes its songs. Why does that need a loop over Songs too?
Support: Build 1 together; pairs do the heading and Make it yours.
A school app has a Classes table and a Students table. What field would link each student to their class, and how would you show one class's students?
A class field on each student. For each student, if their class is the chosen class, add them to a results table.
Next: the SQL course, where linked tables are searched with JOIN.