这篇文章主要为大家详细介绍了SQL Server 删除重复行的6个方法,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
1.如果有ID字段,就是具有唯一性的字段代码如下:
delect table where id not in (
select max(id) from table group by col1,col2,col3...
)
代码如下:
select * into #aa from table group by id1,id2,....
delete table
insert into table
select * from #aa
代码如下:
select identity(int,1,1) as id,* into #temp from tabel
delect # where id not in (
select max(id) from # group by col1,col2,col3...)
delect table
inset into table(...)
select ..... from #temp
代码如下:
select * from table where col1+','+col2+','...col5 in (
select max(col1+','+col2+','...col5) from table
where having count(*)>1
group by col1,col2,col3,col4
)
代码如下:
select identity(int,1,1) as id,* into #temp from tabel
select * from #temp where id in (
select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)
代码如下:
select distinct * into #temp from tablename
delete tablename
go
insert tablename select * from #temp Sqlclub
go
drop table #temp
本文来自:http://www.q1010.com/179/8045-0.html
注:关于SQL Server 删除重复行的6个方法的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:SQL SERVER
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。