Level 4 - Mid-LevelOptimization Questions
Optimization: Filter Placement with LEFT JOIN
Choose better query preserving all customers while counting PAID orders. Query A: SELECT c.id, COUNT(o.id) FROM customers c LEFT JOIN orders o ON c.id = o.customer_id WHERE o.status = 'PAID' GROUP BY c.id; Query B: SELECT c.id, COUNT(o.id) FROM customers c LEFT JOIN orders o ON c.id = o.customer_id AND o.status = 'PAID' GROUP BY c.id;