【发布时间】:2017-02-11 00:24:28
【问题描述】:
在我的 SQL 5.5 中:
尝试创建一个表,该表是表 A 和 B 的 INNER JOIN 和表 C 和 B 的 (UNION) RIGHT JOIN 的结果。
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。