Illustrative Example: A JOIN for a Book Club App
This is an illustrative example: an invented learner, an invented app and made-up data, written to show how a JOIN problem typically appears in a first project and how it gets solved. Nothing here describes a real person or organisation.
The project
Learner A runs a small book club and decides to build a web page that shows what each member is currently reading. They have already created two tables in SQLite:
| members.id | name |
|---|---|
| 1 | Priya |
| 2 | Tom |
| 3 | Wen |
| books.id | title | reader_id |
|---|---|---|
| 10 | The Dispossessed | 1 |
| 11 | Piranesi | 2 |
| 12 | Circe | 1 |
books.reader_id points to members.id, so each book records who is reading it.
The first attempt
Learner A's first query loads members, then, inside a loop in the app, runs one more query per member to fetch their books. It works, but the code is long and Wen, who is not reading anything, shows up with an empty line that looks like an error.
Discovering the JOIN
A mentor suggests asking the database to combine the tables in one query:
SELECT members.name, books.title
FROM members
JOIN books ON books.reader_id = members.id;
Result:
| name | title |
|---|---|
| Priya | The Dispossessed |
| Priya | Circe |
| Tom | Piranesi |
One query instead of four, and the code shrinks to a few lines. But Wen has disappeared entirely.
The decision point: should Wen appear?
Learner A thinks about the page. It is meant to show the whole club, so Wen should appear with "nothing yet". That calls for a LEFT JOIN, which keeps every member even without a matching book:
SELECT members.name, books.title
FROM members
LEFT JOIN books ON books.reader_id = members.id
ORDER BY members.name;
Now Wen appears with a NULL title, and the page shows "Not reading anything right now" when the title is missing.
A small surprise
Later, a member's name is changed in the members table, and Learner A notices the page updates everywhere at once. Because the name lives in one place and books only store the member's id, nothing else needs fixing. That is the reason the tables were split in the first place.
What the example shows
| Step | Lesson |
|---|---|
| Loop with one query per member | Works, but slow and wordy as data grows |
| INNER JOIN | One query; drops members without books |
| LEFT JOIN | Keeps everyone; shows NULL where there is no match |
| ORDER BY | Makes the page tidy and predictable |
Numbers in this example
All rows and names are made up for illustration. The point is the pattern, not the data.
Try it yourself
Recreate the two tables, then add a fourth member and two more books. Predict the row count for the INNER JOIN and the LEFT JOIN before running each. The JOIN row counting notes and the comparison of JOIN types will help you check your reasoning.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.
Illustrative example: the organisations, people, projects and results described on this page are hypothetical. They do not describe a real client or engagement, and no consulting services are offered here.