BeginnerCoder

Lesson 16 — LEFT JOIN: keep rows without a match

LEFT JOIN: keep rows that have no match

An INNER JOIN drops rows with no partner: a customer with no orders vanishes. A LEFT JOIN keeps every row of the left table; where no match exists, the right table's columns are NULL (SQL's "no value", shown as None in Python). COALESCE(x, 0) replaces NULL with 0.

SELECT a.name, p.title
FROM authors a LEFT JOIN posts p ON p.author_id = a.id

Why it matters: "customers who never ordered" and "products never sold" are only visible with a LEFT JOIN — often the most valuable rows in a report.

Want it another way?
Task

Change JOIN to LEFT JOIN so Cy (no orders) also appears, with 0 orders. Expected: Ann 2, Bo 1, Cy 0.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Databases & SQL

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.