Practice · History · Medium
Return every UNESCO site and its governorate’s population_millions — or NULL when we have no population row for that governorate. Order by site name.
Runs in your browser. No signup needed.
unesco_sites LEFT JOIN governorates on governorate = name. A LEFT JOIN keeps all left-side rows, filling NULLs where there is no match.
SELECT u.site, g.population_millions
FROM unesco_sites u
LEFT JOIN governorates g ON u.governorate = g.name
ORDER BY u.site;
The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.
The difference between JOIN and LEFT JOIN is whether unmatched left-side rows survive — a classic source of “missing data” bugs. (SQLite docs)