The growth team wants to distinguish registered customers who have placed an order from those who have only signed up.
The customers table contains registered customers, while the orders table records their orders. Prepare a report listing every registered customer who has placed at least one order, regardless of its status. A customer with several orders should appear only once.
Ordering: Sort by customer_id in ascending order.
Returncustomer_id
About this problem
You practise an existence test. The growth team wants every registered customer in customers who has at least one row in orders, whatever its status, listed once by customer_id and sorted. The question is yes or no for each customer, so the skill is checking that a matching order exists without letting the number of orders shape the result. Orders placed under ids that are not in customers play no part in the answer.
The obvious query is an INNER JOIN from customers to orders. It finds the right customers, but it returns one row per matching order, so a customer with two orders appears twice. The list looks right at a glance, because every customer in it is correct. Patching it with DISTINCT hides the duplicates but not the real issue: the prompt asks whether an order exists, and a join answers how many. Two other slips are worth checking. Filtering on status, such as keeping only paid orders, wrongly drops a customer whose only order was cancelled. Selecting ids straight from orders instead of customers includes customers who never registered.
Read the lesson: EXISTS & Anti-Joins (P08) →