Interview › IN vs EXISTS
SQL interview: IN vs EXISTS vs JOIN
A subquery that can return NULL makes NOT IN return no rows. EXISTS does not have that mood.
Prompt. Customers who have at least one shipped order.
Hint: WHERE EXISTS (SELECT 1 FROM Orders o WHERE …)
SELECT c.customer_id, c.email
FROM Customers c
WHERE EXISTS (
SELECT 1 FROM Orders o
WHERE o.customer_id = c.customer_id
AND o.status = 'Shipped'
);
A JOIN can duplicate customers if they have two shipped orders. EXISTS will not.
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free