sql >> Base de Datos >  >> RDS >> PostgreSQL

Eliminar duplicados en 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
        );