longterm, your strategy should be to remove relation_id and make the other two a composite primary key
for now, you will want to run this --
Code:
create table keepers
select min(relation_id) as min_rel
, user_id
, product_id
from yourtable
group
by user_id
, product_id
having count(*) > 1
;
delete yourtable
from yourtable
, keepers
where yourtable.user_id = keepers.user_id
and yourtable.product_id = keepers.product_id
and yourtable.relation_id > keepers.min_rel
;
as always, before you run any sql that changes data, it's a good idea to take a backup first