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.
Learn SQL on Mimo
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
SELECTandWHEREknowledge - 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.
SQL
DELETE FROM users
WHERE user_id = 42;
This removes only the matching row.
The same pattern works for multiple rows.
SQL
DELETE FROM orders
WHERE status = 'cancelled';
A good safety habit is previewing the target rows first.
SQL
SELECT *
FROM orders
WHERE status = 'cancelled';
What to look for:
DELETE FROMtargets the tableWHERElimits which rows are removed- Missing
WHEREremoves all rows - Preview with
SELECTfirst - Great for cleanup and record removal
Examples you can copy
Delete one user
SQL
DELETE FROM users
WHERE email = 'alex@example.com';
Delete expired sessions
SQL
DELETE FROM sessions
WHERE expires_at < NOW();
Delete test orders
SQL
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:
SQL
DELETE FROM users;
Why it breaks: every row in the table is removed.
Corrected approach:
SQL
DELETE FROM users
WHERE user_id = 42;
Mistake 2: Using the wrong filter column
What the reader might do:
SQL
DELETE FROM orders
WHERE created_at = 'cancelled';
Why it breaks: the filter never matches the intended rows.
Corrected approach:
Use the correct business column.
SQL
WHERE status = 'cancelled';
Mistake 3: Deleting before previewing
What the reader might do:
SQL
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 FROMto remove rows - Always add a
WHEREclause - Preview rows with
SELECTfirst - Missing
WHEREdeletes everything - Use soft deletes when recovery matters
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot