SQL Join Types Explained Using a Small Hospital Database in PostgreSQL

A tutorial published on DEV Community uses a practice hospital database with 10 patients, 10 doctors, and 10 appointments to explain how SQL joins work in PostgreSQL. The database intentionally omits foreign key constraints to illustrate that joins operate purely on matching values at query time, independent of referential integrity rules. Two patients and three doctors with no appointment records serve as test cases to demonstrate how different join types handle unmatched rows. An INNER JOIN returns only the 10 matched appointment rows, silently excluding the five people with no counterpart on the other side. A LEFT JOIN returns 12 rows, preserving all patients including the two without appointments by filling unmatched columns with NULL values.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in