Customers with orders but nothing delivered
Medium
Show the name of customers who have placed at least one order, but none of their orders has the status delivered.
Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)
Your query✔ Solved
Show the expected result
| name |
|---|
| Bikash Thapa |
1 row
Show a solution
SELECT c.name FROM customers c WHERE EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id) AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id AND o.status = 'delivered');
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.