Program Club

FULL OUTER JOIN with SQLite

proclub 2020. 12. 25. 00:11
반응형

FULL OUTER JOIN with SQLite


SQLite only has INNER and LEFT JOIN.

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


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

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.

ReferenceURL : https://stackoverflow.com/questions/1923259/full-outer-join-with-sqlite

반응형