过滤重复数据
2017-04-18 本文已影响0人
Asa_Guo
--1.创建临时表
select *
into #Tmp
from
--过滤重复数据,留下相同记录中ID最小的一条数据。比如name相同的记录,我要ID最小的
(select *
from [HL7].[dbo].Test a
where not exists
(select 1
from [HL7].[dbo].Test
where Name = a.Name and ID < a.ID)
) as table1
--2.删除旧表
drop table [HL7].[dbo].Test
--3.还原旧表
select * into [HL7].[dbo].Test from #Tmp
--4.删除临时表
drop table #Tmp