Medium SQL joins practice Shop database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

name
Emma Clark
Ravi Kumar

Rows can come in any order. Column names do not have to match.

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.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.