问题
SQLite only has INNER and LEFT JOIN.
Is there a way to do a FULL OUTER JOIN with SQLite?
回答1:
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
回答2:
Following Jonathan Leffler's comment, here's an alternative answer to that of Mark Byers':
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
See here for original source and further SQLite examples.
来源:https://stackoverflow.com/questions/1923259/full-outer-join-with-sqlite