创建临时表
create table tmp_dur as
select a.shop_id,a.city_id,a.product_id,max(a.id) as mid from 51fanli_tuandh_item as a group by a.shop_id,a.city_id,a.product_id having count(*) > 1
查询联合表
SELECT a.shop_id,a.city_id,a.product_id from tmp_dur a , 51fanli_tuandh_item b where a.shop_id = b.shop_id and a.city_id = b.city_id and a.product_id = b.product_id
删除重复项目
delete from 51fanli_tuandh_item
where 51fanli_tuandh_item.id != (
SELECT b.mid from tmp_dur b
where 51fanli_tuandh_item.city_id = b.city_id and 51fanli_tuandh_item.shop_id = b.shop_id and 51fanli_tuandh_item.product_id = b.product_id
);
删除临时表
drop tmp_dur;
添加唯一
ALTER TABLE `51fanli_tuandh_item` ADD UNIQUE (
`shop_id` ,
`city_id` ,
`product_id`
);