select distinct a from (select a from table1 union select b from table1 union select c from table1 union select d from table1 ) t1
select a from table1 union select b from table1 union select c from table1 union select d from table1
-- union已经去掉了重复值,所以不需要再次查询了。 -- test: create table #t(a varchar(10),b varchar(10),c varchar(10),d varchar(10)) insert #tselect 'aa','bb','bb','dd'select distinct a from ( select a from #t union all select b from #t union all select c from #t union all select d from #t ) t-- orselect a from #t union select b from #t union select c from #t union select d from #tdrop table #t
union
select b from table1
union
select c from table1
union
select d from table1
) t1
union
select b from table1
union
select c from table1
union
select d from table1
-- test:
create table #t(a varchar(10),b varchar(10),c varchar(10),d varchar(10))
insert #tselect 'aa','bb','bb','dd'select distinct a
from
(
select a from #t
union all
select b from #t
union all
select c from #t
union all
select d from #t
) t-- orselect a from #t
union
select b from #t
union
select c from #t
union
select d from #tdrop table #t