PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Elimina i duplicati in 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
        );