Problem Statement
In a LEFT JOIN, where should you place a filter on the right table's column to avoid unintentionally turning it into an INNER JOIN?
Explanation
Filters on the right table that go in WHERE will eliminate NULL-extended rows and effectively collapse the join to INNER. Put such filters inside ON so unmatched rows are still preserved.
Use WHERE only for predicates that should apply after the join, such as filtering by a left table column.
Code Solution
SolutionRead Only
SELECT c.id, o.id AS order_id FROM customers c LEFT JOIN orders o ON o.customer_id = c.id AND o.status = 'PAID' WHERE c.active = 1;
