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

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

上面写着

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 'outer join airports on airlines.iaco_code = airports.iaco_code full outer join' at line 4

语法对我来说很合适。我以前从来没有做过很多连接,但我需要一个表中的这些列,这些列由各种 id 交叉引用。

最佳答案

MySQL 中没有 FULL OUTER JOIN。见 7.2.12. Outer Join Simplification和 12.2.8.1. JOIN Syntax :

You can emulate FULL OUTER JOIN using UNION (from MySQL 4.0.0 on):

with two tables 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

with three tables 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

https://stackoverflow.com/questions/2384298/

相关文章:

mysql - 何时在 mysql 中使用 TEXT 而不是 VARCHAR

php - 在 Android 上运行 AMP (apache mysql php)

sql - 在 MySQL 中重命名外键列

php - 基于信誉实现权限

sql - 如何选择一个空的结果集?

mysql - 如何将两列与mysql中的现有列名合并为一?

mysql - 如果需要太长时间,如何停止 MySQL 查询?

mysql - 我应该只坚持使用 AWS RDS 自动备份还是数据库快照?

mysql - 如何在 MySQL 中获得减去 6 周的时间戳?

mysql - 将 MySQL 数据库置于版本控制之下?