Eduard
Eduard

Reputation: 9165

How to delete certain amount of last rows in the table in PostgreSQL?

Without referencing the SERIAL id.

Something like:

delete from users LAST 3

which would delete last 3 rows from the table.

Upvotes: 7

Views: 10325

Answers (1)

Bilal Dekar
Bilal Dekar

Reputation: 3966

This will work :

  DELETE
  FROM users 
  WHERE id in (
      SELECT id 
      FROM users 
      ORDER BY id desc
      LIMIT 3
     )

Upvotes: 11

Related Questions