Left Join
A LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table, along with matching rows from the right table - if there's no match, the right table's columns are filled with NULL.
Basic Syntax
SELECT c.first_name, o.amount
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id;
This returns every customer, even those who haven't placed any orders - for those customers, o.amount will simply be NULL.
Finding Rows With No Match
A common pattern is combining a LEFT JOIN with a check for NULL to find rows in the left table that have no corresponding match in the right table:
-- Customers who have never placed an order
SELECT c.first_name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
When to Use a Left Join
Use a LEFT JOIN whenever you want to preserve all records from one table regardless of whether a related record exists - such as listing all products even if some have never been ordered.
"Left" refers to the table listed first in the FROM clause - swapping the table order changes which side is preserved.