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.
DELETE FROM Employees WHERE Department = 'Sales';
| Step | Row ID | Department | WHERE Condition (Department='Sales') | Action |
|---|---|---|---|---|
| 1 | 1 | HR | False | Keep row |
| 2 | 2 | Sales | True | Mark for deletion |
| 3 | 3 | IT | False | Keep row |
| 4 | 4 | Sales | True | Mark for deletion |
| 5 | 5 | Marketing | False | Keep row |
| 6 | - | - | - | Delete rows marked for deletion (Row IDs 2,4) |
| 7 | - | - | - | End of DELETE command |
| Variable | Start | After 1 | After 2 | After 3 | After 4 | After 5 | Final |
|---|---|---|---|---|---|---|---|
| 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] |
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.
DELETE statement with a WHERE condition do in SQL?age is greater than 30 from a table named employees?products with rows:{id:1, name:'Pen', stock:10}, {id:2, name:'Pencil', stock:0}, {id:3, name:'Eraser', stock:5}DELETE FROM products WHERE stock = 0;
DELETE FROM orders WHERE;
users with columns id, name, and status. You want to delete all users whose status is either 'inactive' or 'banned'. Which query correctly deletes these users?DELETE FROM users WHERE status = 'inactive' OR 'banned'; -- OR 'banned' (literal string) evaluates to true, deleting all rows.DELETE FROM users WHERE status IN ('inactive', 'banned'); -- correctly matches either value.DELETE FROM users WHERE status = 'inactive' AND status = 'banned'; -- AND condition is impossible, deletes none.DELETE FROM users WHERE status = 'inactive', 'banned'; -- invalid comma syntax.Pass the test and this pattern moves unknown