码迷,mamicode.com
首页 > 数据库 > 详细

mysql删除重复数据

时间:2018-10-08 15:02:23      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:src   nbsp   rom   mysq   重复数据   tab   sel   mysql   having   

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删除重复数据

标签:src   nbsp   rom   mysq   重复数据   tab   sel   mysql   having   

原文地址:https://www.cnblogs.com/jason123/p/9753951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!