An Outer Join is a type of database join (commonly used in SQL) that returns records from one or both tables even if there’s no matching record in the other table.
LEFT OUTER JOIN (or simply: LEFT JOIN):
→ Returns all records from the left table, and the matching ones from the right table.
→ If there’s no match, the result is filled with NULL values from the right table.
RIGHT OUTER JOIN (or: RIGHT JOIN):
→ Returns all records from the right table, and the matching ones from the left table.
→ If there’s no match, NULL is used for the left side.
FULL OUTER JOIN:
→ Returns all records from both tables, with NULL where no match exists on either side.
Suppose you have two tables:
Customers
| CustomerID | Name |
| 1 | Anna |
| 2 | Bernd |
| 3 | Clara |
Orders
| OrderID | CustomerID | Product |
| 101 | 2 | Book |
| 102 | 4 | Lamp |
| CustomerID | Name | OrderID | Product |
|---|---|---|---|
| 1 | Anna | NULL | NULL |
| 2 | Bernd | 101 | Book |
| 3 | Clara | NULL | NULL |