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
);
网友评论