Beginner

716. DELETE with WHERE

Learn how to delete only selected records by using the WHERE clause.

📘 Lesson 715 of 728 ⏱ 6 min 🎯 Beginner

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons