Build the mental model
A JOIN combines tables through key relationships. `INNER JOIN` returns matches on both sides, while `LEFT JOIN` preserves every row from the left side. Joining multiple one-to-many relationships can multiply rows, so define the result grain before aggregating.
Connect it to a real scenario
Join tutorials to lessons to list lessons for every published tutorial. Use LEFT JOIN when tutorials with no lessons must remain visible, and avoid putting right-table filters in WHERE when that would erase unmatched rows.
Try the working example
SELECT
t.tutorial_id,
t.title AS tutorial_title,
l.lesson_number,
l.title AS lesson_title
FROM app.tutorials AS t
LEFT JOIN app.lessons AS l
ON l.tutorial_id = t.tutorial_id
WHERE t.is_published = true
ORDER BY t.title, l.lesson_number;Each published tutorial appears with its lessons in a deterministic order.5-minute try-it
LEFT JOIN users to enrollments and include users who have not enrolled in anything.
One important caution
Filtering a right-side column in WHERE after a LEFT JOIN can silently turn the result into INNER-JOIN behavior.
PostgreSQL — Joins Between Tables — PostgreSQL Global Development Group