CodeBlanks Logo Icon CodeBlanks

Stock report

Write the UPDATE query that recomputes stock level.

Updating stock

To change the stock quantity you use UPDATE. qty is updated after a sale or a delivery.

UPDATE inventory
SET qty = qty - 5
WHERE id = 1;

This query removes 5 from product 1.

In inventory, qty = qty - 5 is updated. Only the rows where id = 1 holds are affected.

Updating stock — details

SET qty = qty - 5 subtracts 5 from the old quantity. This is the standard way to reduce stock after a sale.

Practice Updating stock

Reduce qty by 5 for id=1 in inventory.

Starter code

query.sql
-- reduce stock
UPDATE inventory
SET
WHERE id = 1

Sample solution

query.sql
UPDATE inventory
SET qty = qty - 5
WHERE id = 1

Expected output

1 satır güncellendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Stock report: match the terms

Term Meaning
UPDATE update
SET new value
- subtract
WHERE condition

2 What is done to reduce stock?

  • SET qty = qty - n Correct answer
  • DELETE
  • DROP
  • INSERT

Explanation: UPDATE SET qty = qty - n reduces stock.

3 Reduce quantity

Question
UPDATE inventory
SET qty = qty ____ 5
WHERE id = 1;
Answer
UPDATE inventory
SET qty = qty - 5
WHERE id = 1;

Explanation: qty = qty - 5 subtracts 5 from the current quantity.

All lessons in Beginner