Back to Practice
#0174
Find Rows Without Matches Using NOT EXISTS
MediumSQL25 min20 XP
Problem
Return customers who have no orders.
Why This Matters
NOT IN can behave surprisingly when the subquery contains NULL; NOT EXISTS is safer for missing-match queries.
Schema
customers(id INTEGER, name TEXT); orders(customer_id INTEGER)
Examples
Example 1
Inputcustomers 1,2,3; orders for 1 and NULL
Outputcustomers 2 and 3
The NULL order customer_id should not prevent valid customers from appearing.
Constraints
- Return the exact requested output.
- Handle ordinary edge cases.
- Prefer simple, interview-readable code.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputcustomers 1,2,3; orders for 1 and NULL
Expectedcustomers 2 and 3
The NULL order customer_id should not prevent valid customers from appearing.
Hidden Test Categories
empty or minimal inputduplicates or tieslarger input