A join is how you ask one question across two tables. The database keeps patients in one table and appointments in another, because storing the patient's name on every appointment row would mean fixing it in ten places when it's misspelled. A join puts them back together for the length of one query.
That's the whole idea. The part that takes practice is that there are several kinds of joins, and they disagree about what to do with rows that have no partner on the other side. Pick the wrong one and rows quietly disappear from your result, and nothing warns you.
This article uses a small hospital database I built for practice: 10 patients, 10 doctors, 10 departments, 10 appointments, 10 prescriptions. Small on purpose, so you can count the rows and see which join dropped what.
The tables
CREATE SCHEMA city_hospital;
SET search_path TO city_hospital;
CREATE TABLE patients (
patient_id INT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
age INT,
g
Discussion
Start the conversation
Your voice can be the first to spark an engaging conversation.