1. 程式人生 > >mysql刪除重復數據

mysql刪除重復數據

刪除重復數據 sel code mysql delete div rom 重復數 max

DELETE
FROM
    table
WHERE
    id IN (
        SELECT
            src.id
        FROM
            (
                SELECT
                    t1.id
                FROM
                    table t1
                WHERE
                    (
                        t1.col1,
                        t1.col2,
                        t1.col3,
                        t1.col4,
                        t1.col5
                    ) 
IN ( SELECT col1, col2, col3, col4, col5 FROM table GROUP
BY col1, col2, col3, col4, col5 HAVING count(*) > 1 ) AND t1.id NOT
IN ( SELECT MAX(id) FROM table GROUP BY col1, col2, col3, col4, col5 HAVING count(*) > 1 ) ) src );

mysql刪除重復數據