TOPIC 13/2816 MINNOT STARTED

Join fan-out: when a total on the screen is too big

A join can repeat a row once for each match, and a sum then counts it again. Learn to state the table grain, spot a wrong total, and test the cases that expose it.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a shop receipt. If the customer's name is printed once for every item, counting the lines counts items, not customers. The number looks tidy and answers the wrong question.

Daily List is a to-do list app. A task can have many comments. Tom, the tester, checks a total on the screen against one table before he trusts it. (SYNTHETIC / TRAINING ONLY: Daily List and the people here are invented.).

What it is: is what a join does when one row has many partners. (Structured Query Language) is the language that asks the question. A table is a grid. A row is one record. A column is one fact, such as minutes spent. The join repeats the task once per comment, and a sum then adds the minutes once per comment. The neighbour is a count taken from the task table alone, with no join. That count cannot repeat a task.

Why it matters: The screen can say the minutes are 50 when the tasks add to 60. Nothing looks broken. A is that repeated number. Tom compares it with the single-table sum. The of that sum is one task.

PLAIN WORDS · 1 in this section
multiplication
repeated adding of the same amount

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB A shop receipt that prints a customer name for each item.

  1. Grain
  2. Compare
  3. Retest
Shop receipt

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A customerA task
A line for each itemA joined row
Counting linesA count of rows
Counting names onceA count of distinct ids

WHERE THIS PICTURE STOPS

  • A receipt is paper, but a query repeats rows silently.
  • A customer buys a few items, but a task can have hundreds of comments.
  • A cashier sees repeats, but a total hides them.

HOOK

Count what you mean.

TELL A FRIEND

A receipt: lines are items, not customers.

OFTEN MIXED UP WITH Join types in depth: what each join keeps, and what to test. That topic goes through join types. This one explains why a join can make a total too big.

PRACTISE AND KEEP

Sources for this topic — 3 sources
  1. Market practice

    Table expressions and joined tables (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL reference: a join returns one row for every pair of rows that meet the condition, so a row with several partners appears several times (search excerpt, page not opened)

    The PostgreSQL reference for joined tables: inner, left, right, full and cross joins, and how an ON condition differs from a WHERE condition in an outer join. Official project documentation. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    SELECT command reference (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL select reference: the where clause filters rows before grouping and the having clause filters groups after grouping (search excerpt, page not opened)

    The PostgreSQL reference for the select command, including the where, group by and having clauses. Official project documentation. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Implementation-specific

    PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: queries-table-expressions and functions-aggregate. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.

    A free, precise, section-numbered description of the SQL a payments practitioner actually writes. Join types and what happens to unmatched rows, GROUP BY and HAVING against WHERE, window functions and the de-duplication and running-total idioms built on them. Transaction isolation levels and the anomalies each permits, index use, and null three-valued logic.

    Used here for the data-and-SQL questions a Payment Operations Analyst, a Production Support Analyst and a Sanctions Screening Analyst are asked. · Checked 2026-08-18

    An implementation, not the standard — which is the point. ISO/IEC 9075-2 is paywalled, and this documents the same constructs in text anybody can open. Its isolation-level chapter attributes to the standard explicitly, so it can carry a standard-level claim as long as the citation says which document it is quoting.

    Cited as market practice rather than an official standard by kind: an engine's manual is authoritative about that engine and is not the obligation. Where a question turns on behaviour PostgreSQL chose rather than behaviour SQL requires, the answer has to say so.

    One correction carried here because it circulates widely: the sentence "The fundamental difference between WHERE and HAVING…", quoted all over the internet as PostgreSQL documentation, is not in the current documentation. It was searched for in the source tree and is not there.

    Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.

    Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.

    Read from the postgres/postgres documentation source tree (doc/src/sgml), which the project itself maintains and which carries the section ids the published URLs are derived from — so a cited section id can be checked against the rendered page.

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.