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 o.order_id, o.status, and o.total_amount for orders that have no matching rows in order_items. Order by order_id.
Result columns · in this order
order_id | Order this line item belongs to; repeats across items. |
status | Order status: paid, shipped, pending, or refunded. |
total_amount | Order total in dollars. |
How to approach it
LEFT JOIN order_items AS oi, then WHERE oi.order_id IS NULL keeps orders with no items.
Sample input
| order_id | status | total_amount |
|---|---|---|
| 1001 | paid | 80 |
| 1003 | pending | 40 |
| 1006 | refunded | 60 |
| 1009 | pending | 30 |
| 1011 | paid | 110 |
| 1012 | shipped | 75 |
6 rows — all rows shown.
| order_id | sku |
|---|---|
| 1001 | SKU-A |
| 1002 | SKU-C |
| 1004 | SKU-A |
| 1010 | SKU-G |
4 rows — all rows shown.
Expected output
| order_id | status | total_amount |
|---|---|---|
| 1003 | pending | 40 |
| 1006 | refunded | 60 |
| 1009 | pending | 30 |
| 1011 | paid | 110 |
| 1012 | shipped | 75 |
5 rows — all rows shown.
Constraints
LEFT JOIN orders to order_items on order_id, then keep only rows where order_items.order_id IS NULL. This is a referential gap check (orders missing their detail rows).
Expected skills
The anti-join pattern as a referential-integrity check: finding parent rows with no child rows.
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.