Joins and grouping: check data across tables
Data often sits in several tables. A join puts rows side by side and GROUP BY counts them. Learn the checks that catch missing and doubled rows.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: two class lists. One list has every student. Another has marks. To see each student with a mark, you match the names. A student with no mark is missing from the match, unless you ask to keep every student. Then you count how many marks each student has.
Daily List is a to-do list app. Tasks live in one table and lists live in another. Tom, the tester, has to put them side by side before a count means anything.
What it is: A join puts rows from two tables side by side where a key matches. (Structured Query Language) is the language the join is written in. A table is a grid, a row is one item, and a column is one fact about that item. An are the pair to keep straight. An inner join keeps only matches. A left join keeps every row from the left table, and it leaves blanks where the other table has no match.
Why it matters: An inner join can hide the row Tom is looking for. A join on a sloppy key can double rows, so a count comes out too high. Tom uses the join he meant, then he checks the count against a count he already trusts.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)
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 Matching two lists and counting the matches, like class lists and marks.
- Join
- Group
- Compare
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Matching names | A join |
| Keeping all students | A left join |
| Counting marks | GROUP BY |
| Only more than one | HAVING |
WHERE THIS PICTURE STOPS
- Names are unique, but join keys may not be.
- A list is short, but tables are large.
- You can see a list, but a query shows only what it asks for.
HOOK
Match, count, compare.
TELL A FRIEND
Two lists: match them, then count.
OFTEN MIXED UP WITH Looking at data with SQL SELECT. That topic reads one table. This one reads rows across tables and counts them.
PRACTISE AND KEEP
Sources for this topic — 2 sources
- Market practice
PostgreSQL documentation: 7.2 Table Expressions ↗ — PostgreSQL Global Development Group · PostgreSQL documentation: the ON of an outer join is not equivalent to WHERE, because an outer join adds rows for unmatched inputs as well as removing rows (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). 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.
- Implementation-specific
PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: queries-table-expressions §7.2 and ddl-constraints. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.
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/postgresdocumentation 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.