CODE WORKSPACE

Orders with no line items

Return o.order_id, o.status, and o.total_amount for orders that have no matching rows in order_items. Order by order_id.

LEFT JOIN order_items AS oi, then WHERE oi.order_id IS NULL keeps orders with no items.

Sample input

ordersAll 12 orders (order_id, status, total_amount shown).
order_idstatustotal_amount
1001paid80
1003pending40
1006refunded60
1009pending30
1011paid110
1012shipped75
order_itemsDistinct order_ids that have items: 1001, 1002, 1004, 1005, 1007, 1008, 1010.
order_idsku
1001SKU-A
1002SKU-C
1004SKU-A
1010SKU-G

Expected output

Expected outputOrders whose order_id never appears in order_items — the referential gaps.
order_idstatustotal_amount
1003pending40
1006refunded60
1009pending30
1011paid110
1012shipped75

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.

Expected skills

The anti-join pattern as a referential-integrity check: finding parent rows with no child rows.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.