CodeBlanks Logo Icon CodeBlanks

Multi-column UPDATE

Update several columns in one UPDATE.

Update with WHERE

With WHERE you filter which rows to update. All matching rows change.

UPDATE products
SET category = 'indirim'
WHERE price < 10;

This query sets category to 'sale' for all products cheaper than 10.

In products, category = 'indirim' is updated. Only the rows where price < 10 holds are affected.

Update with WHERE — details

WHERE can update many rows at once. Write the condition carefully; a wrong condition makes unwanted changes.

Practice Update with WHERE

Set category to 'sale' for products cheaper than 10 in products.

Starter code

query.sql
-- conditional update
UPDATE products
SET
WHERE

Sample solution

query.sql
UPDATE products
SET category = 'indirim'
WHERE price < 10

Expected output

3 satır güncellendi

Questions and answers

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

1 Multi-column UPDATE: match the terms

Term Meaning
UPDATE update
SET new value
WHERE condition
comma separate

2 Conditional update

Question
UPDATE products
SET category = 'indirim'
WHERE ____;
Answer
UPDATE products
SET category = 'indirim'
WHERE price < 10;

Explanation: price < 10 is the right answer.

3 What does UPDATE products SET price=0 WHERE price < 5 do?

  • Sets every price to 0
  • Sets the price to 0 for items cheaper than 5 Correct answer
  • Nothing
  • Raises an error

Explanation: matching rows are updated.

All lessons in Beginner