TOPIC 12/3016 MINNOT STARTED

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.

  1. Pick the two tables
  2. Name the key match
  3. Choose inner or left
  4. Check the row count
  5. Check for no-match rows
Joining two tables

HOW THE PICTURE MAPS

How each part of the picture matches the work
In the pictureIn the work
The guest listOne table, such as users
The seating chartThe other table, such as tasks
Matching by a guest numberJoining on a key
A guest with no seatA row with no match, shown by a left join
A guest listed twice at a tableA 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.

What each part of the trick stands for
In the trickWhat it stands for
CountCheck the row count
Repeated keyA 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
  1. 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.

    §7.2 joined tables, grouping and grouping sets. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    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.

  2. 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.

    §5.5 CHECK/NOT NULL/UNIQUE/primary/foreign keys. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    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.

  3. 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.

    §11.7 expression index example lower(col), affected maintenance and non-HOT update scope. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  4. Simplified educational illustration

    Payments Signal editorial teaching models — Payments Signal

    This site's own simplified teaching models. · Checked 2026-07-12

    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.