CodeBlanks Logo Icon CodeBlanks

Calculating total

Write the query that computes the cart total.

Updating quantity

To change a cart line's quantity you use UPDATE. WHERE picks which row to update.

UPDATE cart
SET qty = 3
WHERE id = 1;

This query sets the quantity of line 1 to 3.

In cart, qty = 3 is updated. Only the rows where id = 1 holds are affected.

Updating quantity — details

Changing quantity is the most common cart operation. Without WHERE every row updates; be careful.

Practice Updating quantity

Set qty to 3 for the line with id=1 in cart.

Starter code

query.sql
-- update quantity
UPDATE cart
SET
WHERE id = 1

Sample solution

query.sql
UPDATE cart
SET qty = 3
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 Calculating total: match the terms

Term Meaning
UPDATE update
SET new value
WHERE condition
INSERT insert

2 Which statement updates the quantity?

  • INSERT
  • DELETE
  • SELECT
  • UPDATE Correct answer

Explanation: UPDATE changes the quantity.

3 New quantity

Question
UPDATE cart
____ qty = 3
WHERE id = 1;
Answer
UPDATE cart
SET qty = 3
WHERE id = 1;

Explanation: The quantity is updated with UPDATE cart SET qty = 3; WHERE picks the row.

All lessons in Beginner