当前位置:Gxlcms > 数据库问题 > 查询和删除数据表中重复数据的sql

查询和删除数据表中重复数据的sql

时间:2021-07-01 10:21:17 帮助过:47人阅读

设计不周产生的,增加唯一索引列即可解决。
技术分享
技术分享  2、这类重复问题通常要求保留重复记录中的第一条记录,操作方法如下
技术分享
技术分享  假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集
技术分享
技术分享select identity(int,1,1) as autoID, * into #Tmp from tableName
技术分享
技术分享select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
技术分享
技术分享select * from #Tmp where autoID in(select autoID from #tmp2)
技术分享
技术分享  最后一个select即得到了Name,Address不重复的结果集(但多了一个autoID字段,实际写时可以写在select子句中省去此列)
技术分享
技术分享(四)
技术分享查询重复
技术分享
技术分享select * from tablename where id in (select id from tablename group by id 
技术分享
技术分享having count(id) > 1)

查询和删除数据表中重复数据的sql

标签:删除重复数据   sql语句删除重复数据   

人气教程排行