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

求一SQL语句能够查询不重复数据
想请问你一下:
例如:#t1表中有字段mesid ,值 99 100 97 45 43 100
#t2表中有字段 mesid ,值 101 100 99 98 97 ...... 45 44 43 42 ...... 4 3 2 1
想要得到 99 100 97 45 43 101 98 96 95 94 ...... 46 44 42 41 40 ...... 4 3 2 1
sql server数据库
那SQL语句怎么写呢?
谢谢 了啊





------解决方案--------------------
SQL code
create table #t1(mesid int)
insert #t1
select 10 union all
select 9

create table #t2(mesid int)
insert #t2
select 9 union all
select 8 union all
select 7

select id=identity(int,1,1),mesid into #t3 from
(
select mesid from #t1
union all
select mesid from #t2
) as a

select mesid from #t3 a where id=(select min(id) from #t3 where mesid=a.mesid) order by id
/*
10
9
8
7
*/

drop table #t1,#t2,#t3