I have a postgresql table without primary key.
I want to remove all entries that have the same id, but retain the most recent one.
The following statement almost works:
DELETE FROM mytable USING mytable t
WHERE mytable.id = t.id AND mytable.modification < t.modification;
Problem: when two entries have the same modification timestamp (which is possible), both are retained. What would I have to change to just keep one of them, does not matter which one?
I cannot change the condition to AND mytable.modification <= t.modification; as this would then remove all dublicates not retaining any entry.