</>
Skip to content
PostgreSQL lessons (14/38)

PostgreSQL — Delete

Basic Delete

DELETE FROM users WHERE id = 1;

Delete All Rows

DELETE FROM users;

With Subquery

DELETE FROM users 
WHERE id IN (SELECT id FROM inactive_users);

Returning

DELETE FROM users 
WHERE id = 1 
RETURNING *;

Using Limit

DELETE FROM logs 
WHERE created_at < '2024-01-01' 
LIMIT 1000;

Truncate vs Delete

FeatureDELETETRUNCATE
SpeedSlowerFaster
WHERE clauseYesNo
RETURNINGYesNo
TriggersYesNo
RollbackYesYes

Truncate

TRUNCATE TABLE logs;
TRUNCATE TABLE logs RESTART IDENTITY;

Mini Practice

  1. Delete specific rows
  2. Delete all rows
  3. Use RETURNING
  4. Compare DELETE and TRUNCATE

Up Next

Continue with Order By — sorting results.

Related Topics

Frequently Asked Questions about Delete

What is Delete in PostgreSQL?

Delete is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Delete?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Delete.

Why is Delete important in PostgreSQL?

Delete is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.