这个union all 怎么写

nettt 2012-09-05 01:25:25
我有两笔完全不同数据,

A表查询数据列是 a1,a2,a3

B表查询数据列是 B1,b2,b3

如何把数据整理显示成 a1,a2,a3,B1,b2,b3

在线等
...全文
133 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
renolit 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
SQL code
declare @tb1 table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb1
select 'a1','a2','a3'

declare @tb2 table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb2
select……
[/Quote]
我的失误,多谢指出
以学习为目的 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

SQL code
select * from a
union all
select * from b
[/Quote]

这种union all效果是


declare @tb1  table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb1
select 'a1','a2','a3'

declare @tb2 table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb2
select 'B1','b2','b3'

select * from @tb1
union all
select * from @tb2

/*
col1 col2 col3
a1 a2 a3
B1 b2 b3
*/
以学习为目的 2012-09-05
  • 打赏
  • 举报
回复
declare @tb1  table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb1
select 'a1','a2','a3'

declare @tb2 table(col1 char(2),col2 char(2),col3 char(2))
insert into @tb2
select 'B1','b2','b3'

select * from @tb1,@tb2

/*
col1 col2 col3 col1 col2 col3
a1 a2 a3 B1 b2 b3

*/
luochaowei1987 2012-09-05
  • 打赏
  • 举报
回复
select * from A,B where ...
yibey 2012-09-05
  • 打赏
  • 举报
回复
select * , null as b1,null as b2,null as b3 from A
union all
select null as a1,null as a2,null as a3,* from B
fengxiaohan211 2012-09-05
  • 打赏
  • 举报
回复
顶楼上两位
renolit 2012-09-05
  • 打赏
  • 举报
回复
select * from a
union all
select * from b
xuam 2012-09-05
  • 打赏
  • 举报
回复
select * from A,B

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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