Multi-column UPDATE
- SQL course
- Beginner
- Lesson 79/115
- 4 min
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
-- conditional update
UPDATE products
SET
WHERESample solution
UPDATE products
SET category = 'indirim'
WHERE price < 10Expected 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
UPDATE products
SET category = 'indirim'
WHERE ____;
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.