How to Delete Data in SQL

Use the DELETE statement when rows should be permanently removed from a table. This is the standard way to delete one record, multiple matching records, or clear table data based on a condition.

What you’ll build or solve

You’ll learn how to delete data in SQL using DELETE, WHERE, and safe filtering patterns. You’ll also know how to avoid deleting more rows than intended.

When this approach works best

This approach is the right choice when existing rows should be removed but the table structure must stay intact.

Common real-world scenarios include:

  • Removing inactive users
  • Deleting canceled orders
  • Clearing test records
  • Removing duplicate rows
  • Resetting temporary tables

This is a bad idea when you only want to archive data or mark it as inactive. In that case, an UPDATE soft-delete flag is often safer.

Prerequisites

You only need:

  • A SQL table with existing rows
  • Basic SELECT and WHERE knowledge
  • Permission to modify table data

Step-by-step instructions

Step 1: Delete rows with a WHERE condition

Always start with a condition to target only the rows you want.

DELETE FROM users
WHERE user_id = 42;

This removes only the matching row.

The same pattern works for multiple rows.

DELETE FROM orders
WHERE status = 'cancelled';

A good safety habit is previewing the target rows first.

SELECT *
FROM orders
WHERE status = 'cancelled';

What to look for:

  • DELETE FROM targets the table
  • WHERE limits which rows are removed
  • Missing WHERE removes all rows
  • Preview with SELECT first
  • Great for cleanup and record removal

Examples you can copy

Delete one user

DELETE FROM users
WHERE email = 'alex@example.com';

Delete expired sessions

DELETE FROM sessions
WHERE expires_at < NOW();

Delete test orders

DELETE FROM orders
WHERE is_test = TRUE;

Common mistakes and how to fix them

Mistake 1: Forgetting the WHERE clause

What the reader might do:

DELETE FROM users;

Why it breaks: every row in the table is removed.

Corrected approach:

DELETE FROM users
WHERE user_id = 42;

Mistake 2: Using the wrong filter column

What the reader might do:

DELETE FROM orders
WHERE created_at = 'cancelled';

Why it breaks: the filter never matches the intended rows.

Corrected approach:

Use the correct business column.

WHERE status = 'cancelled';

Mistake 3: Deleting before previewing

What the reader might do:

DELETE FROM sessions
WHERE expires_at < NOW();

Why it breaks: a bad filter can remove valid data.

Corrected approach:

Run the same SELECT first.

Troubleshooting

If too many rows were deleted, check for a missing or weak WHERE.

If nothing deletes, confirm the filter actually matches existing values.

If the action should be reversible, use soft deletes with UPDATE.

If performance is slow, make sure the filtered column is indexed.

Quick recap

  • Use DELETE FROM to remove rows
  • Always add a WHERE clause
  • Preview rows with SELECT first
  • Missing WHERE deletes everything
  • Use soft deletes when recovery matters