合并两张表

durking 2008-12-10 11:34:10
请问大虾,我现在有两张表
表A 结构为 COLUMN1,COLUMN2,COLUMN3
表B 结构为 COLUMN1,COLUMN2

SELECT * FROM 表A
COLUMN1,COLUMN2,COLUMN3
A1 A2 A3

SELECT * FROM 表B
COLUMN1,COLUMN2
B1 B2


现在我能不能写一条sql 同时查询表A,表B
结果为
COLUMN1,COLUMN2,COLUMN3
A1 A2 A3
B1 B2 null
...全文
62 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Usher2006 2008-12-10
  • 打赏
  • 举报
回复
select * from A
union all
select * , null from B
dawugui 2008-12-10
  • 打赏
  • 举报
回复
select * from a
union all
select * , null from b
Rewiah 2008-12-10
  • 打赏
  • 举报
回复
select * from 表A 
union all
select *,null from 表B


dawugui 2008-12-10
  • 打赏
  • 举报
回复
select * from a
union all
select * , column3 = '' from b
csdyyr 2008-12-10
  • 打赏
  • 举报
回复
SELECT COLUMN1,COLUMN2,COLUMN3 FROM A
UNION ALL
SELECT COLUMN1,COLUMN2,NULL FROM B
nalnait 2008-12-10
  • 打赏
  • 举报
回复
UNION
UNION ALL
linguojin11 2008-12-10
  • 打赏
  • 举报
回复

使用union all
连接表的时候
表字段的数量必须一样多
select * from a
union all
select *,null from b
ws_hgo 2008-12-10
  • 打赏
  • 举报
回复
使用union all
连接表的时候
表字段的数量必须一样多
select * from a
union all
select *,null from b

22,207

社区成员

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

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