Conditional UPDATE
- SQL course
- Beginner
- Lesson 78/115
- 4 min
Make UPDATE conditional with WHERE.
Multi-column update
With SET you can update several columns separated by commas.
UPDATE products
SET price = 10, stock = 50
WHERE id = 1;This query sets price to 10 and stock to 50.
In products, price = 10, stock = 50 is updated. Only the rows where id = 1 holds are affected.
Multi-column update — details
Each column = value pair is separated by a comma. Order does not matter; multiple columns change at once.
Practice Multi-column update
Set price=10 and stock=50 for id=1 in products.
Starter code
-- update two columns
UPDATE products
SET
WHERE id = 1Sample solution
UPDATE products
SET price = 10, stock = 50
WHERE id = 1Expected 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 Two columns
UPDATE products
SET price = 10____ stock = 50
WHERE id = 1;
UPDATE products
SET price = 10, stock = 50
WHERE id = 1;
Explanation: In SET, several columns are updated at once, separated by commas.
2 What separates pairs in multi-column update?
- A comma Correct answer
- A semicolon
- A space
- A colon
Explanation: Column pairs are separated by commas.
3 Conditional UPDATE: match the terms
| Term | Meaning |
|---|---|
UPDATE |
update |
SET |
new value |
comma |
separate columns |
WHERE |
condition |