1.查找重复记录:

(按id查找)

select * from user_info 
  where 
  id in
  (
     select id from user_info
     group by 
       id 
     having count(id)>1
  )

即:select * from user_info where id in(select id from user_info group by id having count(id)>1)

2.删除重复记录:

    不保留重复记录,只需把上面的select * from 改成 delete from 就可以了。

  保留一条重复记录:

delete from user_info 
where name in (select name from user_info group by name    having count(name) > 1) 
and   
id not in (select min(id) from user_info group by name having count(name)>1)

 

相关文章:

  • 2022-02-21
  • 2021-12-08
  • 2021-11-29
  • 2021-09-30
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2021-07-30
  • 2021-12-18
  • 2021-04-04
  • 2021-07-01
相关资源
相似解决方案