0
0
SQLquery~10 mins

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

Choose your learning style9 modes available
Concept Flow - DELETE with WHERE condition
Start DELETE command
Check WHERE condition on each row
Mark row
Delete marked rows
End
The DELETE command checks each row against the WHERE condition. Rows that match are deleted; others stay.
Execution Sample
SQL
DELETE FROM Employees WHERE Department = 'Sales';
Deletes all rows from Employees table where Department is 'Sales'.
Execution Table
StepRow IDDepartmentWHERE Condition (Department='Sales')Action
11HRFalseKeep row
22SalesTrueMark for deletion
33ITFalseKeep row
44SalesTrueMark for deletion
55MarketingFalseKeep row
6---Delete rows marked for deletion (Row IDs 2,4)
7---End of DELETE command
💡 All rows checked; rows with Department='Sales' are deleted.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
Rows in Employees[1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,2:Sales,3:IT,4:Sales,5:Marketing][1:HR,3:IT,5:Marketing]
Key Moments - 2 Insights
Why are only some rows deleted and not all?
Only rows where the WHERE condition is True are deleted, as shown in execution_table rows 2 and 4. Rows with False condition remain.
What happens if the WHERE condition is missing?
Without WHERE, all rows would be deleted. Here, the WHERE condition filters rows to delete only those matching 'Sales'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which row IDs are deleted?
A1 and 3
B2 and 4
C3 and 5
DAll rows
💡 Hint
Check the 'Action' column where rows are marked for deletion.
At which step does the DELETE command remove rows?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look for the step mentioning 'Delete rows marked for deletion'.
If the WHERE condition was Department = 'IT', which rows would be deleted?
ARow 3 only
BRows 1 and 5
CRows 2 and 4
DNo rows
💡 Hint
Refer to the 'Department' values in the variable_tracker and execution_table.
Concept Snapshot
DELETE FROM table_name WHERE condition;
- Checks each row against condition.
- Deletes only rows where condition is true.
- Without WHERE, deletes all rows.
- Use carefully to avoid data loss.
Full Transcript
The DELETE command removes rows from a table that meet a specific condition given by WHERE. It checks each row one by one. If the condition is true, that row is deleted. If false, the row stays. For example, DELETE FROM Employees WHERE Department = 'Sales' deletes only employees in Sales. The execution table shows each row checked and action taken. Rows 2 and 4 match and are deleted. Rows 1, 3, and 5 do not match and remain. This selective deletion helps avoid removing all data accidentally. Always use WHERE to target specific rows.