Write each query here, and run it on a real Postgres database in your browser.
Save who watched which video in a join table, and read it from both sides.
Scenario
Simplified saves each video a learner finishes watching. You save new ones, then answer who watched what.
Simplified keeps learners in users, videos in videos, and one row in watches each time a learner finishes a video.
Can you save a new pair, and find who watched what?
Each row of watches holds two ids: the learner's user_id, and the video_id of what they watched.
Eli, whose id is 5, finishes two videos.
They are Memory and disk, whose id is 2, and Queries and results, whose id is 3.
Save both pairs with one INSERT.
Fay, whose id is 6, finishes Servers, whose id is 1.
An assistant tried to save that in Fay's row of users.
Predict what Postgres does, run it, then save the pair where it belongs.
The team checks what Ada, whose id is 1, has watched.
Send back the title of every video Ada has watched.
Next, the team checks who has watched Servers, whose id is 1.
Send back the name of every learner who has watched it.
The team asks how many learners have watched Queries and results.
Send back that one number, finding that row of videos by its title.
Last, the team wants to see how many learners have watched each video.
Send back each video_id, with how many rows of watches it has.
column "video_id" of relation "users" does not exist
users has no video_id column.
A pair goes in watches, as one new row.
missing FROM-clause entry for table "users"
The query names users, but never reads it.
Add it after JOIN: FROM watches JOIN users.
insert or update on table "watches" violates foreign key constraint "watches_video_id_fkey"
The video_id matches no id in videos, so Postgres refuses the row.
videos holds ids 1 to 8.
Each step passes once its query sends back the right rows, or makes the right change. Then mark the lab complete to unlock the next lesson.