日期:2014-05-18  浏览次数:20512 次

删除重复字段
select id 
from T
where NAME='T'
GROUP BY ID
HABING COUNT (ID)>=2

如何删除上表中
重复的字段
如重复1条 删除1条
重复2 则删除2
始终保持该表中1条唯一记录

------解决方案--------------------
alter table T add rowid int identity(1,1)
go

delete a from T a where exists(select 1 from T where id=a.id and rowid<a.rowid)
go

alter table T drop column rowid
go
------解决方案--------------------
select distinct id into #
TRUNCATE TABLE t
insert into t select * from #
drop table #