Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Return customer_id and country for customers with at least one shipped order.
Result columns · in this order
customer_id | Stable customer identifier. |
country | Customer country. Can be NULL when unknown. |
How to approach it
Use WHERE EXISTS against orders filtered to shipped.
Sample input
| customer_id | country |
|---|---|
| 1 | US |
| 2 | null |
| 3 | GB |
| 4 | IN |
| 6 | GB |
5 rows — all rows shown.
| order_id | buyer_id | status |
|---|---|---|
| 1004 | 1 | shipped |
| 1008 | 4 | shipped |
| 1012 | 3 | shipped |
3 rows — all rows shown.
Expected output
| customer_id | country |
|---|---|
| 1 | US |
| 3 | GB |
| 4 | IN |
3 rows — all rows shown.
Constraints
Use EXISTS correlated on customer_id. Order by customer_id.
Expected skills
Correlated subqueries and semi-join reasoning.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.