求一SQL语句实现两个表合并
两个表个结果一样,但是字段名字不一样.
tb_a:的字段有a1,a2,a3
tb_b:的字段有b1,b2,b3
实现把tb_b合并到tb_a中,b1对应a1,b2对应a2,b3对应a3.
如:
tb_a表
a1 a2 a3
1 2 3
11 22 33
-------黄金分割线----------
tb_b表
b1 b2 b3
b b b
bb bb bb
执行我求的SQL语句后tb_a表的内容
tb_a表
a1 a2 a3
1 2 3
11 22 33
b b b
bb bb bb
谢谢大家了
------解决方案--------------------select * from tb_a
union all
select * from tb_b
------解决方案--------------------declare @tb_a table(a1 varchar(10),a2 varchar(10),a3 varchar(10))
insert @tb_a
select 1,2,3 union all
select 11,22,33
declare @tb_b table(b1 varchar(10),b2 varchar(10),b3 varchar(10))
insert @tb_b
select 'b ', 'b ', 'b ' union all
select 'bb ', 'bb ', 'bb '
select * from @tb_a
union all
select * from @tb_b
------解决方案--------------------如此应该可以对应吧:
select a1,a2,a3 from @tb_a
union all
select b1,b2,b3 from @tb_b
------解决方案--------------------declare @tb_a table(a1 varchar(10),a2 varchar(10),a3 varchar(10), a4 varchar(10))
insert @tb_a
select 1,2,3,4 union all
select 11,22,33,44
declare @tb_b table(b1 varchar(10),b2 varchar(10),b3 varchar(10))
insert @tb_b
select 'b ', 'b ', 'b ' union all
select 'bb ', 'bb ', 'bb '
select top 1 * from @tb_a
select top 1 * from @tb_b
select * from @tb_a
union all
select *,null from @tb_b