mysql 删除重复数据,保留一个

delete from custom_review_record where id in

(
select t.id from (
select min(id) as id, COUNT(reportId) as num from custom_review_record where nodeId = '02f30dbc-ebc7-4dda-9287-4143163881c5' GROUP BY reportId having num > 1
) t
)

1. 查找同一个记录,主键最小的值

select min(id) as id, COUNT(reportId) as num from custom_review_record where nodeId = '02f30dbc-ebc7-4dda-9287-4143163881c5' GROUP BY reportId having num > 1

2.把ID做为缓存表,直接关联删除

delete from custom_review_record where id in (select t.id from (***) t

posted @ 2021-11-05 15:45  JOKI丶  阅读(78)  评论(0)    收藏  举报