Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
组合mysql表_Mysql_Union - Fatal编程技术网

组合mysql表

组合mysql表,mysql,union,Mysql,Union,如何组合表X和Y: table X (columnA, columnB, columnC) table Y (columnA, columnB, columnD) 获取(列A、列B、列C、列D) 我希望看到空值 更具体地说,以下是各表的内容: tableX: A B C 1 | 0 | 0 2 | 0 | 0 tableY: A B D 3 | 0 | 0 4 | 0 | 0 result: A B C D 1 | 0 | 0 | NULL 2 | 0 | 0

如何组合表
X和Y

table X (columnA, columnB, columnC)
table Y (columnA, columnB, columnD)
获取(列A、列B、列C、列D)

我希望看到空值

更具体地说,以下是各表的内容:

tableX:
A   B   C
1 | 0 | 0
2 | 0 | 0

tableY:
A   B   D
3 | 0 | 0
4 | 0 | 0

result:
A   B   C   D
1 | 0 | 0 | NULL
2 | 0 | 0 | NULL
3 | 0 | NULL | 0
4 | 0 | NULL | 0

如果两个表(x&y)的
列A
都被引用,则使用下面的

SELECT x.columnA,x.columnB,x.columnC,y.columnD
FROM tableX x
LEFT JOIN tabley y ON y.columnA=x.columnA

我认为他不希望加入,只是连接:

SELECT columnA, columnB, columnC, null as columnD
FROM tableX
UNION ALL
SELECT columnA, columnB, null as columnC, columnD
FROM tableY

这很好,除了在tableZ(columnA,columnB,columnC,null)表中columnD将被命名为“null”之外