The WHERE clause limits the DELETE operation to rows that satisfy a specified condition. Without WHERE, all rows are removed from the table.
Most business scenarios require deleting only specific records rather than removing the entire dataset.
A company removes only employees who belong to the Temporary department.
DELETE FROM Employees
WHERE Department = 'Temporary';
Organizations delete cancelled orders, inactive customers, duplicate records, expired sessions, and obsolete inventory using conditional DELETE statements.
- Deletes only matching rows.
- Uses the WHERE clause.
- Prevents accidental deletion of all records.
- Supports multiple conditions.
- Works with AND and OR operators.
- Can use comparison operators.
- Preview records using SELECT before DELETE.
Why should DELETE usually include a WHERE clause?
The WHERE clause ensures that only the intended records are deleted.
How can you verify which rows will be deleted?
Run a SELECT statement with the same WHERE condition before executing DELETE.