合并具有不同列数的两个表 [英] Unioning two tables with different number of columns

查看:96
本文介绍了合并具有不同列数的两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表(表A和表B).

I have two tables (Table A and Table B).

这些具有不同的列数-假设表A具有更多列.

These have different number of columns - Say Table A has more columns.

如何合并这两个表,并为表B没有的列获取空值?

How can I union these two table and get null for the columns that Table B does not have?

推荐答案

为具有较少列的表添加额外的列作为null

Add extra columns as null for the table having less columns like

Select Col1, Col2, Col3, Col4, Col5 from Table1
Union
Select Col1, Col2, Col3, Null as Col4, Null as Col5 from Table2

这篇关于合并具有不同列数的两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆