TOPIC 14/3015 MINNOT STARTED

Join fan-out: why a total comes out too big

A join can repeat a row once for every match, and a sum then counts it again. Learn the grain of a table, how to spot the repeat, and three safe fixes.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a bill and its receipts. One bill can have three receipts. If you add the bill amount once per receipt, you add it three times. The pile of paper got taller. The money did not.

Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). Sam, the , joins each task to its comments. Nina, the , wants the total minutes. The join can repeat a task’s minutes. Here50joined minutes overstates the commented tasks’30minutes, while100minutes across all tasks is a different population.

What it is: (Structured Query Language) is a language for asking a database questions. A table is a grid, a row is one record, and a column is one fact. Fan-out means one row on the left becomes many rows after a join, because the right side has many matches. is what one row stands for, such as one task or one comment. An inflated total is a sum or a count that grew because rows were repeated. You see it in the query result. The neighbour is a join that still has one row per task.

Why it matters: The joined count can equal the original task count by chance, so the count does not warn you. The sum still lies. Sam would tell Nina that commented tasks took 50 minutes. Those tasks took 30 minutes. The 100 minutes cover all tasks.

A paper bill is easy to spot twice. A query prints one number, and the repeat is hidden inside it.

PLAIN WORDS · 1 in this section
overstates
describes as bigger than it is

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 A class register listing a pupil once for every lesson.

  1. State
  2. Compare
  3. Fix
Class register

HOW THE PICTURE MAPS

How each part of the picture matches the work
In the pictureIn the work
A pupilA task
A line for each lessonA joined row
Counting linesCOUNT of rows
Counting names onceCOUNT of distinct ids

WHERE THIS PICTURE STOPS

  • A register is on paper, but a query can repeat rows silently.
  • A pupil has a few lessons, but a task can have hundreds of comments.
  • A teacher sees the repeat, but a total hides it.

HOOK

Count the thing you mean.

TELL A FRIEND

A receipt total repeats when one task joins to several comments. Compare the same measure for the same population, and reduce the child to one row per parent or use .

OFTEN MIXED UP WITH Join types in depth: inner, left, full, cross and self. That topic compares join types. This one explains why a join can inflate a total.

PRACTISE AND KEEP

Sources for this topic — 3 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

    Aggregate functions (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, §9.21 aggregates, NULL and empty input; publisher page opened6November 2026. Dialect scope explicit.

    §9.21 aggregates, NULL and empty input. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §9.21 aggregates, NULL and empty input. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

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