sql >> Base de Datos >  >> RDS >> Mysql

MySQL elimina filas duplicadas

DELETE FROM comments c1 

WHERE EXISTS (
    SELECT * 
    FROM comments c2 
    WHERE c2.id <> c1.id 
        AND c2.name = c1.name 
        AND c2.email = c1.email 
        AND c2.comment = c1.comment
)

AND c1.id <> (
    SELECT MIN(c2.id) 
    FROM comments c2 
    WHERE c2.name = c1.name 
        AND c2.email = c1.email 
        AND c2.comment = c1.comment
)