🗃️Left Join
Also known as LEFT JOIN, Left Outer Join
A join that keeps each row from the first table, with a match or not.
Think of it like
Think of it like a class photo. All the kids are in it, even if their mum did not come.
Example
Lucy wants to email people who have never ordered. A left join shows all customers, and the empty totals are her list.
Why it matters
Finding what is missing is a common need. A left join is how you see it.
Definition
Example code
sql
SELECT customers.name, orders.total
FROM customers
LEFT JOIN orders ON orders.customer_id = customers.id;
-- Emma | 25.0
-- Emma | 40.0
-- Jack | 15.5
-- Lucy | NULLCommon mistake
Key takeaways
- 1Keep the left side. Every row from the first table.
- 2NULL for no match. Empty columns show the gap.
- 3Find what is missing. Great for gaps in data.