DELETE
Objectives
By the end of this lesson, you should be able to:
- Remove rows with
DELETE - Explain why
WHEREmatters forDELETE, the same way it does forUPDATE - Explain the difference between
DELETEandTRUNCATE TABLE
💡 Why this matters: Sometimes a row genuinely needs to be gone, an employee who left, a cancelled order.
DELETEremoves rows permanently, which makes it exactly as important to target correctly asUPDATE.
⚠️ A note on verification: every statement and result in this lesson was run against a real, live PostgreSQL 18 database, using the
employeestable from Module 3, filtered withWHERE(covered fully in Module 6).
The DELETE Statement
DELETE FROM employees WHERE first_name = 'Jordan';
first_name
------------
Erin
Maya
Priya
Jordan’s row is gone entirely, not marked inactive, not hidden, permanently removed. WHERE narrows down exactly which rows are deleted, using the same conditions covered fully in Module 6.
Why WHERE Matters Here Too
Just like UPDATE, leaving off WHERE affects every row:
DELETE FROM employees;
This empties the entire table, one row at a time, permanently. Always double-check WHERE before running a DELETE, exactly the same discipline as UPDATE.
DELETE vs. TRUNCATE TABLE
Both remove rows, but they’re not the same tool. DELETE FROM employees; (no WHERE) and TRUNCATE TABLE employees; (from Module 3) both end with an empty table, but DELETE processes and removes rows one at a time and can be limited with WHERE, while TRUNCATE removes everything at once and can’t be filtered at all. For removing a subset of rows, DELETE ... WHERE is the only option, TRUNCATE is all-or-nothing.
Try It
- Delete one specific employee by
first_name, and confirm they’re gone with aSELECT. - Explain, in your own words, the difference between
DELETE FROM table;(noWHERE) andTRUNCATE TABLE table;. - Explain why you can’t use
TRUNCATE TABLEto remove just the employees in one specific department.
Recap
DELETE FROM table WHERE condition;permanently removes matching rows.- Leaving off
WHEREdeletes every row, the same risk as anUPDATEwith noWHERE. DELETEcan target a subset of rows withWHERE,TRUNCATE TABLE(Module 3) always removes everything at once.
Next lesson: the RETURNING clause, seeing exactly which rows an INSERT, UPDATE, or DELETE just affected.