SQL SERVER常用取重复记录的SQL语句
- 获取某字段或几个字段有重复的数据,可限定重复几条
select field1,field2 from table group by field1,field2 having count(field1)>1 - 获取某字段不重复的最新记录
select top * from table a where id in(select max(id) from table b group by field) order by id desc - 获取某字段的重复数
select count(field) from table group by field having count(field)>1 - 获取不重复的记录
select field1,field2 from table group by field1,field2 - 删除重复记录
delete from from table a where id not in(select max(id) from table b group by field)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步