联合两个不同列数的表

2021-11-20 00:00:00 sql mysql

我有两个表(表 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?

推荐答案

为列数较少的表添加额外的列为空,如

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

相关文章