SQL 使用 SQLite 完全外部联接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1923259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:46:35  来源:igfitidea点击:

FULL OUTER JOIN with SQLite

sqlsqlitejoinfull-outer-join

提问by Yada

SQLite only has INNER and LEFT JOIN.

SQLite 只有 INNER 和 LEFT JOIN。

Is there a way to do a FULL OUTER JOIN with SQLite?

有没有办法用 SQLite 进行完全外部联接?

回答by Mark Byers

Yes, see the example on Wikipedia.

是的,请参阅维基百科上的示例。

SELECT employee.*, department.*
FROM   employee 
       LEFT JOIN department 
          ON employee.DepartmentID = department.DepartmentID
UNION ALL
SELECT employee.*, department.*
FROM   department
       LEFT JOIN employee
          ON employee.DepartmentID = department.DepartmentID
WHERE  employee.DepartmentID IS NULL

回答by Adil Hussain

Following Jonathan Leffler's comment in Mark Byers' answer, here's an alternative answer which uses UNIONinstead of UNION ALL:

按照 Jonathan Leffler 在 Mark Byers' answer 中的评论,这里有一个替代答案,它使用UNION代替UNION ALL

SELECT * FROM table_name_1 LEFT OUTER JOIN table_name_2 ON id_1 = id_2
UNION
SELECT * FROM table_name_2 LEFT OUTER JOIN table_name_1 ON id_1 = id_2

Edit:The original source for the SQLite example above and from where further SQLite examples could be found was http://sqlite.awardspace.info/syntax/sqlitepg06.htmbut it seems as though that site is now returning a 404 Not Found error.

编辑:上面 SQLite 示例的原始来源以及可以找到更多 SQLite 示例的位置是http://sqlite.awardspace.info/syntax/sqlitepg06.htm但似乎该站点现在返回 404 Not Found 错误.