美文网首页工作生活
MySQL中删除重复数据只保留一条

MySQL中删除重复数据只保留一条

作者: KengG | 来源:发表于2019-07-01 22:57 被阅读0次
    DELETE FROM brand_group_relation
    WHERE id IN (
            SELECT id
            FROM (
                SELECT id
                FROM brand_group_relation
                WHERE (brand_group_id, brand_value_id) IN (
                        SELECT brand_group_id, brand_value_id
                        FROM brand_group_relation
                        GROUP BY brand_group_id, brand_value_id
                        HAVING COUNT(*) > 1
                    )
                    AND id NOT IN (
                        SELECT MIN(id)
                        FROM brand_group_relation
                        GROUP BY brand_group_id, brand_value_id
                        HAVING COUNT(*) > 1
                    )
                ORDER BY brand_group_id, brand_value_id
            ) tmp
        );
    

    参考

    相关文章

      网友评论

        本文标题:MySQL中删除重复数据只保留一条

        本文链接:https://www.haomeiwen.com/subject/zseocctx.html