SQL DELETE
DELETE removes rows that match a WHERE condition. Like UPDATE, without WHERE it removes everything.
TRUNCATE empties a whole table quickly, and DROP TABLE removes the table itself.
Syntax
DELETE FROM table_name WHERE condition;
Try it yourself
Run the example below on a real PostgreSQL database, then change it and run it again. Nothing to install, no sign-up.
delete.sql · PostgreSQL
Loading editor…
Examples
1. Delete specific rows
DELETE FROM order_items WHERE order_id = 5; SELECT COUNT(*) FROM order_items WHERE order_id = 5;
Order 5 has no lines left (rolled back afterwards).
Common mistakes
- Deleting parent rows that other tables reference (a foreign key error).
Practice: test yourself
This challenge is from our interactive course. Write the query and press Check answer.
Challenge · 20 pts
Delete all order_items that belong to order 5 (and nothing else).
challenge.sql · PostgreSQL
Loading editor…
FAQ
DELETE vs TRUNCATE vs DROP?
DELETE removes chosen rows, TRUNCATE removes all rows, DROP removes the table.
Learn SQL step by step
65 hands-on exercises, streaks, a leaderboard and a certificate.