2017-12-11 14:28:16
删除某个字段(note_id)重复的数据
!--找出重复数据id较小的--
select min(id) from tb group by note_id having count(note_id) > 1
!--执行删除--
delete from tb where id in(select min(id) from tb group by note_id having count(note_id) > 1)
报错:You can’t specify target table ‘tb’ for update in FROM clause
!--修改下sql--
delete from tb where id in (select a.id from (select min(id) id from tb group by note_id having count(note_id) > 1) a)