7

Without referencing the SERIAL id.

Something like:

delete from users LAST 3

which would delete last 3 rows from the table.

1

1 Answer 1

11

This will work :

  DELETE
  FROM users 
  WHERE id in (
      SELECT id 
      FROM users 
      ORDER BY id desc
      LIMIT 3
     )
Sign up to request clarification or add additional context in comments.

2 Comments

This uses the id column.
@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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.