0
0
MySQLquery~10 mins

DELETE with WHERE clause in MySQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - DELETE with WHERE clause
Start DELETE command
Check WHERE condition on each row
Delete row
Repeat for all rows
End DELETE command
The DELETE command checks each row against the WHERE condition. If the condition is true, the row is deleted; otherwise, it stays.
Execution Sample
MySQL
DELETE FROM employees WHERE department = 'Sales';
Deletes all rows from the employees table where the department is 'Sales'.
Execution Table
StepRow IDdepartmentWHERE condition (department='Sales')Action
11SalesTrueDelete row 1
22HRFalseKeep row 2
33SalesTrueDelete row 3
44MarketingFalseKeep row 4
55SalesTrueDelete row 5
6---End of table, DELETE complete
💡 All rows checked; rows with department 'Sales' deleted.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Table rows count5443322
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 1, 3, and 5. Rows with 'False' condition remain.
What happens if the WHERE clause is missing?
Without WHERE, all rows would be deleted. Here, the WHERE clause limits deletion to matching rows only.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 2?
ARow 2 is deleted
BRow 2 is kept
CRow 2 is updated
DRow 2 is ignored
💡 Hint
Check the 'Action' column for step 2 in the execution_table.
At which step does the DELETE command finish checking all rows?
AStep 4
BStep 5
CStep 6
DStep 3
💡 Hint
Look for the row with 'End of table, DELETE complete' in the execution_table.
If the WHERE clause was removed, how would the variable 'Table rows count' change after step 1?
AIt would decrease to 0
BIt would stay the same
CIt would increase
DIt would decrease by 1
💡 Hint
Without WHERE, the condition is always true, so step 1 deletes row 1 like in the table, decreasing the count by 1.
Concept Snapshot
DELETE FROM table_name WHERE condition;
- Deletes rows matching the condition.
- Rows not matching stay unchanged.
- Without WHERE, all rows are deleted.
- Always check condition to avoid unwanted deletions.
Full Transcript
The DELETE command with a WHERE clause checks each row in the table. If the row meets the condition, it is deleted; otherwise, it remains. This example deletes employees in the Sales department. The execution table shows each row checked and action taken. The variable tracker shows the table row count decreasing as rows are deleted. Key points include understanding that only matching rows are deleted and that omitting WHERE deletes all rows. The visual quiz tests understanding of these steps.