Find customers without orders
Return customer_id and name for customers who have no matching order, regardless of order status or amount. An order with a NULL customer_id belongs to no customer. Row order does not matter.
Difficulty: intermediate
Show hint
Use a LEFT JOIN and check for a missing order_id, or use NOT EXISTS. A NULL in a NOT IN subquery can change its result.
Tables and sample data
Each test starts with fresh tables. Result rows may be returned in any order. Column names and column order must match.
| customer_id (integer) | name (text) | city (text) |
|---|---|---|
| 1 | Asha | Kathmandu |
| 2 | Ben | London |
| 3 | Chen | Singapore |
| order_id (integer) | customer_id (integer) | amount (numeric) | status (text) | region (text) |
|---|---|---|---|---|
| 1 | 1 | 50 | paid | East |
| 2 | 3 | 70 | pending | West |
| customer_id | name |
|---|---|
| 2 | Ben |