SQL Practice: Inventory Reorder List
Build an operations list that shows which active products need restocking first.
Inventory queries are where filters and calculated columns become practical. A buyer doesn't need every product. They need active products that are below their reorder level, with the biggest shortfalls first.
The product table has the stock numbers. The category table adds readable context so the reorder list is easier to scan.
Separate stock rules from display columns
The rule is purely numeric:
quantity_on_hand < reorder_level. The calculated
units_short
column turns that rule into a prioritized work queue.
select item_name,
quantity_on_hand,
reorder_level,
reorder_level - quantity_on_hand as units_short
from inventory
where discontinued = false
and quantity_on_hand < reorder_level
order by units_short desc Schema · Garden Shop Tables · products, categories 2 tables
One row per product, with price, cost, and inventory levels.
Lookup table of product categories.
Return active products that need restocking. Include product_name, category_name, quantity_on_hand, reorder_level, and units_short. Sort by units_short descending, then product name.
Run your query to inspect the result.
Expected answer
- Columns: product_name, category_name, quantity_on_hand, reorder_level, units_short.
- Rows: active products below their reorder level.
- The biggest shortfall should appear first.
Related
Comparisons, AND/OR, IN, BETWEEN, and LIKE.
SELECT, WHERE, ORDER BY, and LIMIT at a glance.
UNION ALL, UNION, INTERSECT, and EXCEPT.
Use WHERE to keep only matching rows.
Create derived values in a SELECT list.
Join through a bridge table.