Customers with a pending order
Question
Show the name of every customer who has at least one order with status 'pending'. Each customer once.
customersid, name, country, joined_on
productsid, name, category, price
ordersid, customer_id, ordered_on, status
order_itemsorder_id, product_id, quantity
Your query
Ctrl+Enter to run
Result
Expected result
| name |
|---|
| Emma Clark |
| Ravi Kumar |
Hint
Join customers to orders, filter on the status, and remove duplicates.
Show the solution
solution.sql
Run this code
SELECT DISTINCT c.name
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.status = 'pending';
Why it works
The join produces one row per matching order, so a customer with two pending orders would appear twice. DISTINCT keeps each name once.
Common mistake
Text comparison is exact in =, so 'Pending' with a capital P would match nothing here. Check the real values with SELECT DISTINCT status FROM orders first.