根据MySql中的两列删除重复记录

时间:2017-10-03 10:27:54

标签: mysql group-by group-concat

我想删除多余的重复记录

即。在显示的图片中有两条记录corporate_id = 5category_id = 19,如何删除任何一行重复(此处corporate_sed_id是主键)

enter image description here

1 个答案:

答案 0 :(得分:2)

使用: -

DELETE
FROM
    corporate
WHERE
    corporate_sed_id IN(
    SELECT
        *
    FROM
        (
        SELECT
            MIN(corporate_sed_id)
        FROM
            corporate
        GROUP BY
            corporate_id,
            category_id
        HAVING
            COUNT(corporate_sed_id) > 1
    ) temp
)