SQL for BAs: JOIN
Combine two tables with JOIN. Learn keys, the difference between INNER and LEFT joins, how to find rows with no match, double rows, and what to ask when a query is slow.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a guest list and a seating chart. One list has each guest's email. The other says which seat they get. You match the lists by a number, not by a name that two people might share.
Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). Tasks sit in one table. People sit in another. Sam, the , wants each task with its owner's email.
What it is: (Structured Query Language) is a language for asking a database questions. A table is a grid, a row is one thing, and a column is one fact. A is the step that pairs rows from two tables when a key matches. A foreign key is the column that points at a row in the other table. Here tasks.user_id points at users.id. An inner join keeps only pairs. A left join keeps every row from the left table, even when no pair exists. Those two are easy to mix up.
Why it matters: Mei has no tasks. An inner join hides her, so a report of "all users" is short by one. A filter in the wrong place hides her again after a left join. Sam then tells Nina, the , that everyone has a task.
Matching by name fails when two people share a name. The key exists so the match is exact.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.
THE REAL JOB The picture helps a newcomer remember that a join matches rows by a key, and that a repeated match makes repeated rows.
- Pick the two tables
- Name the key match
- Choose inner or left
- Check the row count
- Check for no-match rows
HOW THE PICTURE MAPS
| In the picture | In the work |
|---|---|
| The guest list | One table, such as users |
| The seating chart | The other table, such as tasks |
| Matching by a guest number | Joining on a key |
| A guest with no seat | A row with no match, shown by a left join |
| A guest listed twice at a table | A repeated row after a join |
WHERE THIS PICTURE STOPS
- Names on a list can match by accident. Keys are exact.
- A seating chart has one seat for each guest. A task table can have many tasks for one user.
- A host can see a double card at once. A join gives no warning.
HOOK
Match by number, keep who you need, count the rows.
REMEMBER IT THIS WAY
A rule of thumb: if you see this, think that.
Count the rows before and after a join. If the count grew, usually a key repeated somewhere.
| In the trick | What it stands for |
|---|---|
| Count | Check the row count |
| Repeated key | A guest listed twice at a table gives a repeated row |
One user with many tasks grows the count by design, so a bigger count is sometimes correct.
TELL A FRIEND
A join combines rows from two tables where the stated join condition is true. An inner join keeps matches only, a left join keeps all rows from one side, and a repeated match makes repeated rows.
OFTEN MIXED UP WITH SQL for BAs: SELECT and WHERE. That topic asks one table questions. This one combines two tables to answer a bigger question.
PRACTISE AND KEEP
Sources for this topic — 4 sources
- Market practice
Table expressions and joined tables (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, §7.2 joined tables, grouping and grouping sets; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §7.2 joined tables, grouping and grouping sets. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
Constraints (PostgreSQL documentation, data definition chapter) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §5.5 CHECK/NOT NULL/UNIQUE/primary/foreign keys; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §5.5 CHECK/NOT NULL/UNIQUE/primary/foreign keys. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
PostgreSQL18: indexes on expressions ↗ — PostgreSQL Global Development Group · PostgreSQL 18: indexes on expressions; §11.7 expression index example lower(col), affected maintenance and non-HOT update scope. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Simplified educational illustration
Payments Signal editorial teaching models — Payments Signal
What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.
Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.