sqlserver 删除表中重复的记录

作者:滴水穿石 | 创建时间: 2023-03-17
本文介绍了怎样查询sqlserver数据库表中重复的记录,以及删除重复的记录...
sqlserver 删除表中重复的记录

操作方法

如图一在数据表中有两个膀胱冲洗重复的记录。

可以通过sql语句“select *from 表名 where 编码 in(select 编码 from 表名 group by 编码 having count(1) >= 2)”来查询出变种所有重复的记录如图二

通过sql语句" delete from 表名 where 编码 in(select 编码 from 表名 group by 编码 having count(1) >= 2) and 编码 not in (select max(编码)from 表名 group by 编码 having count(1) >=2) "来删除重复的记录只保留编码最大的记录

点击展开全文

更多推荐