0
0
SQLquery~10 mins

UPDATE with WHERE condition in SQL - Step-by-Step Execution

Choose your learning style9 modes available
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.
Execution Sample
SQL
UPDATE Employees
SET Salary = Salary + 500
WHERE Department = 'Sales';
This query increases the Salary by 500 for employees in the Sales department only.
Execution Table
StepRow IDCurrent SalaryDepartmentWHERE Condition (Department='Sales')ActionNew Salary
11013000SalesTrueUpdate3500
21023200HRFalseSkip3200
31032800SalesTrueUpdate3300
41044000ITFalseSkip4000
51053100SalesTrueUpdate3600
6----End of rows-
💡 All rows checked; only rows with Department='Sales' updated.
Variable Tracker
Row IDSalary BeforeSalary After
10130003500
10232003200
10328003300
10440004000
10531003600
Key Moments - 2 Insights
Why are some rows not updated even though the UPDATE command runs?
Rows where the WHERE condition is False are skipped, as shown in execution_table rows 2 and 4.
What happens if the WHERE condition is missing?
Without WHERE, all rows would be updated. Here, only rows with Department='Sales' are updated.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the new salary of Row ID 103 after the update?
A3500
B2800
C3300
D3100
💡 Hint
Check the 'New Salary' column for Row ID 103 in the execution_table.
At which step does the WHERE condition evaluate to False?
AStep 2
BStep 3
CStep 1
DStep 5
💡 Hint
Look at the 'WHERE Condition' column in the execution_table for False values.
If the WHERE clause was removed, how would the 'Action' column change?
AAll rows would be 'Skip'
BAll rows would be 'Update'
COnly Sales rows would be 'Update'
DNo rows would be updated
💡 Hint
Without WHERE, UPDATE affects every row as per SQL rules.
Concept Snapshot
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.
Full Transcript
The UPDATE statement changes data in a table. It checks each row against the WHERE condition. If the condition is true, it updates that row's data. If false, it leaves the row unchanged. For example, increasing salary only for employees in the Sales department updates only those rows. Rows in other departments remain the same. Without a WHERE clause, all rows would be updated. This visual shows step-by-step how each row is checked and updated or skipped.