以我SQL 5.5:的MySQL創建一個表內部聯接UNION右連接
試圖建立一個表,該表是一個INNER的結果JOIN表的& B,和(UNION)RIGHT JOIN表的ç& B.
CREATE TABLE IF NOT EXISTS TABLE_NAME AS (
(SELECT a.column1, b.column2 FROM TABLEA AS a
INNER JOIN TABLEB AS b
ON a.column1 = b.column1)
UNION
(SELECT c.column1, b.column2 FROM TABLEC AS c
RIGHT JOIN TABLEB AS b
ON b.column1 = c.column1)
);
錯誤:
ERROR 1064 (42000) at line 11: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT a.column1, b.column2 FROM TABLEA AS a
其他嘗試:
CREATE TABLE IF NOT EXISTS TABLE_NAME AS (
(SELECT a.column1, b.column2 FROM TABLEA AS a
INNER JOIN TABLEB AS b
ON a.column1 = b.column1)
UNION
(SELECT c.column1, b.column2 FROM TABLEC AS c
RIGHT JOIN TABLEB AS b
ON b.column1 = c.column1)
);
Error:
ERROR 1064 (42000) at line 11: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
可以在任何大師提供一些建議?謝謝。
從維恩圖,我想你需要'LEFT JOIN',不'RIGHT JOIN'。 –