183. Customers Who Never Order

Return the names of customers with no orders, as Customers.

NOT EXISTS is an anti-join. NOT IN (SELECT customerId FROM Orders) returns nothing at all if any customerId is NULL.

Lesson: joins.

Solutions

SELECT c.name AS Customers
FROM Customers c
WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.customerId = c.id);