1、最简单的是使用distinct,去除所有查询字段信息一样的数据

    

---------------------------------------以下为有主键的情况下使用

2、 查询,去重,保留最小id信息
select * from people where id in (
    select MIN(id) from people group by name,sex)

 

 

3、 查询全部的重复信息
select * from people where id not in (

    select min(id) from people group by name,sex HAVING COUNT(*) < 2)

 


4、查询多余的重复信息
select * from people where id not in (

    select MIN(id) from people group by name,sex)

 


5、删除多余重复的信息,只保留最小ID
delete from people where id not in(
    select MIN(id) from people group by name,sex
)

相关文章:

  • 2021-12-28
  • 2021-10-17
  • 2022-12-23
  • 2021-10-01
  • 2021-10-02
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-09-10
  • 2022-12-23
  • 2021-11-23
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案