[请教一个问题]不能用union的一句sql语句

smalldeer 2005-01-06 09:59:51
我的一个群上出的一个问题
-------------------------------------
两个表a,b,分别都有test1,test2列
a:
test1 test2
1 1
2 2

b:
test1 test2
3 3
4 4
现在用一句sql,不能用union,筛出来和集
test1 test2
1 1
2 2
3 3
4 4

--------------------------------------
我是想不通,不用union,怎么样把属于不同表的字段放在同个显示列下

请教大家了,谢谢
...全文
204 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
TT008 2005-08-08
  • 打赏
  • 举报
回复
study
lsxaa 2005-01-07
  • 打赏
  • 举报
回复
select distinct isnull(a,c) test1,isnull(b,d) test2
from (select a.test1 a,a.test2 b,b.test1 c,b.test2 d
from a full join b
on a.test1=b.test1 and a.test2=b.test2) t
zlp321002 2005-01-07
  • 打赏
  • 举报
回复
Try:
那就不用SQL解决这个问题,在前台上用两个DataSet合并!
yesyesyes 2005-01-07
  • 打赏
  • 举报
回复
select isnull(a,c) test1,isnull(b,d) test2
from (select a.test1 a,a.test2 b,b.test1 c,b.test2 d from a full join b on a.test1=b.test1) t
order by test1
smalldeer 2005-01-07
  • 打赏
  • 举报
回复
谢谢各位,原来可以这样来解决

增加了思路,谢谢了
NinGoo 2005-01-06
  • 打赏
  • 举报
回复
不用union,那用union all好了,哈哈
smalldeer 2005-01-06
  • 打赏
  • 举报
回复
ps:是别人出的,那人还挺横,说就是不让用union
所以我上来问问大家。
smalldeer 2005-01-06
  • 打赏
  • 举报
回复
不能用临时表吧,我也不知道
既然要求连union都不能用了,那临时表应该也不可以吧

等待...

NinGoo 2005-01-06
  • 打赏
  • 举报
回复
没看清,还只能一句sql,那不能用临时表了
didoleo 2005-01-06
  • 打赏
  • 举报
回复
沙发
NinGoo 2005-01-06
  • 打赏
  • 举报
回复
select * into #tmp from a
isnert into #tmp select * from b

select * from #tmp

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧