select top 1 * into #t from tab1 while exists(select 1 from tab1 a,#t b where a.a<>b.a and a.b<>b.b and a.c<>c.c insert #t select top 1 a.* from tab1 a,#t b where a.a<>b.a and a.b<>b.b and a.c<>c.cselect * from #t
想了想,上面是错的。 select top 1 * into #t from tab1while exists(select 1 from tab1 where a not in (select a from #t) and b not in (select b from #t) and c not in (select c from #t))insert #t select top 1 * from tab1 where a not in (select a from #t) and b not in (select b from #t) and c not in (select c from #t) select * from #t
不明白你在说什么select distinct a,b,c from [tablename]不能满足你的需求?
while exists(select 1 from tab1 a,#t b where a.a<>b.a and a.b<>b.b and a.c<>c.c
insert #t select top 1 a.* from tab1 a,#t b where a.a<>b.a and a.b<>b.b and a.c<>c.cselect * from #t
select top 1 * into #t from tab1while exists(select 1
from tab1
where a not in (select a from #t)
and b not in (select b from #t)
and c not in (select c from #t))insert #t select top 1 *
from tab1
where a not in (select a from #t)
and b not in (select b from #t)
and c not in (select c from #t) select * from #t