OUTER JOIN
Clause
The type of OUTER JOIN
There are two types of OUTER JOIN
, LEFT OUTER JOIN
and RIGHT OUTER JOIN
. Using LEFT OUTER JOIN
, all records from left table we are retrieving will be kept in result table. Using RIGHT OUTER JOIN
, all records from right table we are retrieving will be kept in result table.
OUTER
keyword is optional, usingLEFT
orRIGHT
keyword is consider as aOUTER JOIN
by default.
SQL
SELECT [columns]
FROM
[table1] LEFT OUTER JOIN [table]
ON [condition] -- records from [table1] will be kept in result table
1
2
3
4
2
3
4
SQL
SELECT [columns]
FROM
[table1] RIGHT JOIN [table] -- OUTER keyword is optional
ON [condition]
1
2
3
4
2
3
4
OUTER JOIN
Multiple Tables
SQL
SELECT [columns]
FROM
[table1] LEFT JOIN [table2]
ON [condition1]
LEFT JOIN [table3]
ON [condition2]
1
2
3
4
5
6
2
3
4
5
6
- Do NOT use
RIGHT JOIN
unless you really need to, because we always select columns that are not null and place them in the left side of result table, possible null columns are placed in the right side. UsingLEFT JOIN
is easier to understand.
Self Join
Same as self join of INNER JOIN
.