BeginnerCoder

Lesson 18 — Three-table JOIN

Joining three tables

A many-to-many link — students take many courses, courses have many students — needs a third link table (here enrollments) holding pairs of ids. To get readable names you JOIN all three: students → enrollments → courses. Each JOIN needs its own ON.

FROM readers r
JOIN loans l ON l.reader_id = r.id
JOIN books b ON b.id = l.book_id

Why it matters: tags on posts, products in orders, users in groups — many-to-many is everywhere.

Want it another way?
Task

Add the second JOIN to courses so each row shows the course title. Expected: 4 rows of (student, course).

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Databases & SQL

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.