declare @t table(id int,name varchar(10))
insert into @t
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 1,'a' union all
select 2,'b'
--select * from @t
select distinct * from @t
結果:
id name
----------- ----------
1 a
2 b
3 c
insert into @t
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 1,'a' union all
select 2,'b'
--select * from @t
select distinct * from @t
結果:
id name
----------- ----------
1 a
2 b
3 c
insert into a select '12','44' union all select '12','44' --建表
--result:
a
Pa Ma
12 44
12 44select distinct * into #b from b --提出重复中的一个放入#b
drop table a
select * into a from #b --再把#b放入表a
select * from a --test
2 diatinct a,b
3 分爲幾步如樓上的方法