Both, not either
- O(n log n) · Hard
- Full plan
- SQL
- sets
- subqueries
Problem
Anyone who has ordered a Monitor and a Mouse is putting together a desk setup, and the owner wants to write to them and offer whatever they're still missing. The Monitor is product 3 and the Mouse is product 2. Show the name of each customer who has ordered both products, once per customer. Having ordered just one of them isn't enough, and it doesn't matter how many times or on what dates.
What it has to return
These rows, in any order
| name |
|---|
| Ann |
| Luke |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT customer_id
FROM orders
WHERE product_id = 3;It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.