我有查询,曾经在MariaDB 10.2.15上工作。升级到MariaDB 10.3.7后,此查询不再起作用,我不知道原因。
查询看起来像这样:
WITH
table_1 AS (SELECT id AS 'first_id' FROM some_table),
table_2 AS (select id AS 'second_id' FROM another_table)
SELECT *
FROM table_1
LEFT OUTER JOIN table_2 ON table_1.first_id = table_2.second_id
UNION
SELECT *
FROM table_1
RIGHT OUTER JOIN table_2 ON table_1.first_id = table_2.second_id
如果我尝试运行此查询,则会收到错误Unknown column 'table_2.second_id' in 'on clause'
。现在它变得奇怪了,因为当我修改查询(从连接列中删除别名)到这样的东西(见下文)时,一切正常。
WITH
table_1 AS (SELECT id FROM some_table),
table_2 AS (select id FROM another_table)
SELECT *
FROM table_1
LEFT OUTER JOIN table_2 ON table_1.id = table_2.id
UNION
SELECT *
FROM table_1
RIGHT OUTER JOIN table_2 ON table_1.id = table_2.id
编辑1: 我试图将查询更改为此,但仍然无效。
WITH
table_1 AS (SELECT id AS `first_id` FROM some_table),
table_2 AS (select id AS `second_id` FROM another_table)
SELECT *
FROM table_1
LEFT OUTER JOIN table_2 ON table_1.first_id = table_2.second_id
UNION
SELECT *
FROM table_1
RIGHT OUTER JOIN table_2 ON table_1.first_id = table_2.second_id
编辑2:
我很确定,first_id
列存在,因为当我运行查询时,我可以在检索到的结果中看到所需的列。我想在LEFT OUTER JOIN过程中我的别名列会丢失。
WITH
table_1 AS (SELECT id AS `first_id` FROM some_table),
table_2 AS (select id AS `second_id` FROM another_table)
SELECT *
FROM table_1