6

Without referencing the SERIAL id.

Something like:

delete from users LAST 3

which would delete last 3 rows from the table.

Eduard
  • 8,437
  • 10
  • 42
  • 64
  • 1
    Possible duplicate of [How do I delete a fixed number of rows with sorting in PostgreSQL?](https://stackoverflow.com/questions/5170546/how-do-i-delete-a-fixed-number-of-rows-with-sorting-in-postgresql) – Tim Biegeleisen Mar 25 '18 at 14:27

1 Answers1

10

This will work :

  DELETE
  FROM users 
  WHERE id in (
      SELECT id 
      FROM users 
      ORDER BY id desc
      LIMIT 3
     )
Bilal Dekar
  • 3,200
  • 4
  • 28
  • 53
  • This uses the id column. – Eduard Mar 25 '18 at 19:04
  • @Eduard Which other column do you have in your table that can track the last/most recent rows you have added to the table ? (Note that postgresql itself does not track this information) – nos Mar 25 '18 at 19:22