Skip to content
RED SAGSkills
hard20 pts · first answer countssqljoins

Filter inside the ON clause

customers has 5 rows. Customer 1 has one paid and one refunded order, customer 2 has one paid order, customer 3 has one order with NULL status, customers 4 and 5 have none. How many rows does this return?

SELECT c.id, o.id
FROM customers c
LEFT JOIN orders o
  ON o.customer_id = c.id AND o.status = 'paid';
Choose one answer