D8LooPFocus modeCODE WORKSPACE
Return o.order_id, o.total_amount, and c.country for orders whose status is shipped, joining orders to customers on the buyer. Order by order_id.
JOIN orders AS o to customers AS c ON c.customer_id = o.buyer_id, filter status = 'shipped', then ORDER BY o.order_id.
Sample input
| order_id | buyer_id | status | total_amount |
|---|---|---|---|
| 1003 | 4 | pending | 40 |
| 1004 | 1 | shipped | 220 |
| 1008 | 4 | shipped | 150 |
| 1010 | 6 | paid | 640 |
| 1012 | 3 | shipped | 75 |
| customer_id | country |
|---|---|
| 1 | US |
| 3 | GB |
| 4 | IN |
| 6 | GB |
Expected output
| order_id | total_amount | country |
|---|---|---|
| 1004 | 220 | US |
| 1008 | 150 | IN |
| 1012 | 75 | GB |
Constraints
Join orders to customers on customers.customer_id = orders.buyer_id. Keep only status = 'shipped'. Alias the tables (o, c) and select the three named columns.
Expected skills
Writing an INNER JOIN, expressing the match in ON, and aliasing tables for readable column references.
Run the SQL query to inspect preview rows.