FULL OUTER JOIN with SQLite

2019-01-04 09:24发布

SQLite only has INNER and LEFT JOIN.

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

2条回答
我想做一个坏孩纸
2楼-- · 2019-01-04 09:33

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.

查看更多
\"骚年 ilove
3楼-- · 2019-01-04 09:49

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
查看更多
登录 后发表回答