Concept Flow - UPDATE with WHERE condition
Start UPDATE statement
Check WHERE condition for each row
Update row
End UPDATE
The UPDATE command checks each row against the WHERE condition. If true, it updates that row; if false, it skips it.
UPDATE Employees SET Salary = Salary + 500 WHERE Department = 'Sales';
| Step | Row ID | Current Salary | Department | WHERE Condition (Department='Sales') | Action | New Salary |
|---|---|---|---|---|---|---|
| 1 | 101 | 3000 | Sales | True | Update | 3500 |
| 2 | 102 | 3200 | HR | False | Skip | 3200 |
| 3 | 103 | 2800 | Sales | True | Update | 3300 |
| 4 | 104 | 4000 | IT | False | Skip | 4000 |
| 5 | 105 | 3100 | Sales | True | Update | 3600 |
| 6 | - | - | - | - | End of rows | - |
| Row ID | Salary Before | Salary After |
|---|---|---|
| 101 | 3000 | 3500 |
| 102 | 3200 | 3200 |
| 103 | 2800 | 3300 |
| 104 | 4000 | 4000 |
| 105 | 3100 | 3600 |
UPDATE table_name SET column = new_value WHERE condition; - Only rows matching WHERE condition are updated. - Rows not matching are unchanged. - Omitting WHERE updates all rows.
What does the WHERE clause do in an UPDATE statement?
Which of the following is the correct syntax to update the salary to 5000 for employees with id 3?
UPDATE employees SET salary = 5000 WHERE id = 3;
Given the table products:
id | name | price ---+---------+------- 1 | Pen | 10 2 | Pencil | 5 3 | Eraser | 3
What will be the result of this query?
UPDATE products SET price = price + 2 WHERE price < 10;
Find the error in this query:
UPDATE employees SET salary = 6000 WHERE;
You have a table students with columns id, name, and grade. You want to increase the grade by 5 for all students who scored less than 50, but not exceed 50 after update. Which query correctly does this?
Pass the test and this pattern moves unknown