Total stock including missing items
Return every item name and total quantity, using zero for missing stock, ordered by item id.
Try it yourself
Open a fresh temporary warehouse inventory dataset. Write your query and use Check answer. Checking uses a separate, clean sample so edits to your workspace cannot change the expected answer. Matches are based on this dataset, not a proof for every possible database.
Open exercise →Sample schema
warehouses(id, name) items(id, sku, name, reorder_level) stock(warehouse_id, item_id, quantity) movements(id, item_id, warehouse_id, delta, moved_at)
About this dataset · Learning paths · SQL reference
Show a hint
LEFT JOIN, GROUP BY and COALESCE keep all items.
Show one solution
SELECT i.name, COALESCE(SUM(s.quantity),0) FROM items i LEFT JOIN stock s ON s.item_id=i.id GROUP BY i.id ORDER BY i.id;Other queries can produce the same answer. Column aliases are ignored; column order and row order are checked.