SQL DELETE
DELETE removes rows from a table. Like UPDATE, it acts on every row that matches WHERE, and on all rows if you leave WHERE out.
Updated December 1, 2026
Syntax
DELETE FROM table_name
WHERE condition;
Delete rows that match
Remove cancelled orders, then see what’s left.
DELETE FROM orders
WHERE status = 'cancelled';
Check the result:
SELECT status, COUNT(*) AS orders
FROM orders
GROUP BY status;
| status | orders |
|---|---|
| delivered | 7 |
| shipped | 2 |
Delete using a subquery
Remove products that are out of stock and have never been ordered.
DELETE FROM products
WHERE stock = 0
AND id NOT IN (SELECT product_id FROM order_items);
Check the result:
SELECT COUNT(*) AS products_left
FROM products;
| products_left |
|---|
| 8 |
Common mistakes
- Forgetting
WHEREand emptying the table. Run the condition as aSELECTfirst. - Deleting parent rows (like a customer) that other rows still point to. Delete or reassign the children first, or let a foreign key handle it.
- Using
DELETEto clear a huge table, which is slow.TRUNCATEis faster where it’s supported.
Practice DELETE interactively
Write real queries in your browser and get instant feedback in the lesson “UPDATE and DELETE” (Unit 9). New learners can start free from the first lesson.
Frequently asked questions
DELETE vs TRUNCATE vs DROP?
DELETE removes chosen rows. TRUNCATE removes all rows quickly (not in SQLite). DROP TABLE removes the table itself.
Should I delete or mark rows as deleted?
Many apps “soft delete” with a deleted_at column, so data can be restored and history kept.