A LEFT JOIN keeps all rows from the left table, but placing conditions on the right table in WHERE can remove rows where the right-side value is NULL.
Incorrect filter placement can unintentionally turn a LEFT JOIN into behavior similar to an INNER JOIN.
Find all customers and their orders, but understand how filtering order amounts affects customers without orders.
SELECT
c.CustomerName,
o.OrderID,
o.OrderAmount
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomerID
AND o.OrderAmount > 50000;
This is important in customer analysis, account reporting, compliance checks, and identifying missing relationships.
- LEFT JOIN keeps all left-table rows.
- Right-table filters can be placed in ON.
- A right-table condition in WHERE can remove NULL matches.
- Filter placement changes the result.
- Use ON carefully when unmatched rows must be preserved.
Why can WHERE change a LEFT JOIN result?
A WHERE condition on the right table can remove rows where the right-side columns are NULL.
Where can a right-table filter be placed to preserve unmatched rows?
The condition can often be placed in the ON clause of the LEFT JOIN.