If this is a one-off then you can simply identify the records you want to keep like so:
SELECT MIN(id) AS id
FROM yourtable
GROUP BY object_id, product_id;
You want to check that this works before you do the next thing and actually throw records out. To actually delete those duplicate records you do:
DELETE FROM yourtable WHERE id NOT IN (
SELECT MIN(id) AS id
FROM yourtable
GROUP BY object_id, product_id
);
The MIN(id)
obviously always returns the record with the lowest id for a set of (object_id
, product_id
). Change as desired.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…