求一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语句怎么写呢?
谢谢 了啊
[解决办法]
create table #t1(mesid int)insert #t1select 10 union allselect 9create table #t2(mesid int)insert #t2select 9 union allselect 8 union allselect 7select id=identity(int,1,1),mesid into #t3 from(select mesid from #t1union allselect mesid from #t2) as aselect mesid from #t3 a where id=(select min(id) from #t3 where mesid=a.mesid) order by id/*10987*/drop table #t1,#t2,#t3