SQL OUTER JOIN

Unlike SQL INNER JOIN, SQL OUTER JOIN selects rows from 2 joined tables even there is no matches found.

There are three kind of SQL OUTER JOINs:
SQL LEFT OUTER JOIN
SQL RIGHT OUTER JOIN
SQL FULL OUTER JOIN

SQL OUTER JOIN Example

Table: Employees

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

Table: Email

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

Select all the employees with Email address:

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

The result will look like:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>