MySQL为内部联接UNION创建一个表右联接 [英] MySQL create a table for an inner join UNION right join

查看:74
本文介绍了MySQL为内部联接UNION创建一个表右联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SQL 5.5中:

In my SQL 5.5:

试图创建一个表,该表是表A&的INNER JOIN的结果B和表C&的(联合)右联接B.

Trying to create a table which is a result of a INNER JOIN of table A & B, and (UNION) RIGHT JOIN of table C & 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

任何一位大师都可以提供一些建议吗?谢谢.

Could any guru offer some advice? Thanks.

推荐答案

尝试一下

CREATE TABLE IF NOT EXISTS TABLE_NAME AS 
(
SELECT S.*
FROM
(
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
) S
);

这篇关于MySQL为内部联接UNION创建一个表右联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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