MySQL中删除重复数据只保留一条
2019-07-01 本文已影响0人
KengG
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
);