SQL OUTER JOIN

不象SQL INNER JOIN,SQL OUTER JOIN外联接两个联接表,即使它们没有匹配。

有三种类型的外联接SQL OUTER JOIN:
SQL LEFT OUTER JOIN
SQL RIGHT OUTER JOIN
SQL FULL OUTER JOIN

SQL OUTER JOIN 范例

数据表: Employees

EmployeeId FirstName LastName
203 Aciyy Uioiakk
204 Qiaiiua Nikaiy
205 Iulada Benooo
206 Wiaoooa Yugh

数据表: Email

EmployeeId Email
203 AciyyU@mycomany.com
204 QiaiiuaN@mycomany.com
205 IuladaB@mycomany.com

选择所有的职员(Employee)和Email地址:

SELECT  emp.EmployeeId, emp.FirstName, emp.LastName, Email.Email
FROM Employees AS emp
     LEFT OUTER JOIN Email
     ON emp.EmployeeId = Email.EmployeeId

结果会类似于:

EmployeeId FirstName LastName Email
203 Aciyy Uioiakk AciyyU@mycomany.com
204 Qiaiiua Nikaiy QiaiiuaN@mycomany.com
205 Iulada Benooo IuladaB@mycomany.com
206 Wiaoooa Yugh