3 回答
TA贡献1789条经验 获得超10个赞
是的,请参阅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
TA贡献1784条经验 获得超2个赞
在乔纳森·莱夫勒(Jonathan Leffler)评论之后,这是马克·拜尔斯(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
请参阅此处以获取原始源代码和其他SQLite示例。
TA贡献1883条经验 获得超3个赞
如果使用UNION ALL,则两个选择之一必须排除“内部联接”行,例如所示的WHERE条件,这一点至关重要。或者,您可以使用普通的UNION并消除其重复,以避免重复“内部联接”行。
添加回答
举报