一尘不染

为什么MySQL在FULL OUTER JOIN上报告语法错误?

mysql

SELECT airline, airports.icao_code, continent, country, province, city, website

FROM airlines 
FULL OUTER JOIN airports ON airlines.iaco_code = airports.iaco_code
FULL OUTER JOIN cities ON airports.city_id = cities.city_id
FULL OUTER JOIN provinces ON cities.province_id = provinces.province_id
FULL OUTER JOIN countries ON cities.country_id = countries.country_id
FULL OUTER JOIN continents ON countries.continent_id = continents.continent_id

它说

您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以airports在第4行“ airlines.iaco_code
= airport.iaco_code完全外部联接”附近使用

语法对我来说似乎正确。我以前从未做过很多联接,但是我需要一个表中的那些列,这些列被各种ID交叉引用。


阅读 539

收藏
2020-05-17

共1个答案

一尘不染

FULL OUTER JOINMySQL中没有。见7.2.12。外连接简化12.2.8.1。JOIN语法

您可以FULL OUTER JOIN使用UNION(从MySQL 4.0.0开始)进行仿真:

有两个表t1,t2:

SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id

有三个表t1,t2,t3:

SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
LEFT JOIN t3 ON t2.id = t3.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id
LEFT JOIN t3 ON t2.id = t3.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id
RIGHT JOIN t3 ON t2.id = t3.id
2020-05-17