PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Excluir duplicatas no postgres

DELETE from posts del 
WHERE EXISTS (
        SELECT *
        FROM posts ex
        WHERE ex.external_id = del.external_id
        AND ex.id < del.id -- if you want to keep the lowest id
        -- AND ex.id > del.id -- if you want to keep the highest id
        );