当前,我正在尝试将4个表连接在一起,仅显示5列,并将它们全部合并到一个表中。
这是查询:
SELECT
id,
platform,
url,
profileImageUrl,
name
FROM (
SELECT
f.id AS id,
f.platform AS platform,
f.url AS url,
f.profileImageUrl AS profileImageUrl,
f.name AS name
FROM
`l.p.link_f_main` AS f UNION
SELECT
i.id AS id,
i.platform AS platform,
i.url AS url,
i.profilePicture AS profileImageUrl,
i.fullName AS name
FROM
`l.p.link_i_main` AS i UNION
SELECT
t.id AS id,
t.platform AS platform,
t.url AS url,
t.profileImageUrl AS profileImageUrl,
t.name AS name
FROM
`l.p.link_t_main` AS t UNION
SELECT
y.id AS id,
y.platform AS platform,
y.url AS url,
y.profileImageUrl AS profileImageUrl,
y.name AS name
FROM
`l.p.link_y_main` AS y ) as main
这是错误:
Error: Syntax error: Expected keyword ALL or keyword DISTINCT but got keyword SELECT at [16:3]
我做错了什么?
答案 0 :(得分:1)
答案:
1)对于大查询,必须使用UNION ALL
而不是UNION
2)所有联合列的数据类型应该相同。 -
STRING
-INT64, INT64,
INT64, STRING
STRING
,以使其正常工作。答案 1 :(得分:0)
摘自文档:UNION { ALL | DISTINCT }
。因此,您必须使用UNION ALL
或UNION DISTINCT
(这正是错误消息所说的)。正如HoneyBadger用户提到的那样,这是正确的解释。