位置: 编程技术 - 正文
推荐整理分享SQL去除重复记录(七种)(sql去除重复项),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:sql去除重复项,sql中去除重复记录,sql去除重复记录怎么操作,sql去除重复的数据,sql中去除重复记录,sql语句去除重复记录,sql去除重复数据语句,SQL去除重复记录,内容如对您有帮助,希望把文章链接给更多的朋友!
话不多说,请看代码:
--I、Name相同ID最小的记录(推荐用1,2,3),保留最小一条
方法1:
delete a from #T a where exists(select 1 from #T where Name=a.Name and ID<a.ID)
方法2:
方法3:
delete a from #T a where ID not in (select min(ID) from #T where Name=a.Name)
方法4(注:ID为唯一时可用):
delete a from #T a where ID not in(select min(ID)from #T group by Name)
方法5:
delete a from #T a where (select count(1) from #T where Name=a.Name and ID<a.ID)>0
方法6:
delete a from #T a where ID<>(select top 1 ID from #T where Name=a.name order by ID)
方法7:
标签: sql去除重复项
本文链接地址:https://www.jiuchutong.com/biancheng/320265.html 转载请保留说明!友情链接: 武汉网站建设