bg_image
header

Outer Join

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.

Types of Outer Joins:

  1. 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.

  2. 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.

  3. FULL OUTER JOIN:
    → Returns all records from both tables, with NULL where no match exists on either side.


Example:

Suppose you have two tables:

  • Customers

    CustomerID Name
    1 Anna
    2 Bernd
    3 Clara
  • Orders

    OrderID CustomerID Product
    101 2 Book
    102 4 Lamp

LEFT JOIN (Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID)

CustomerID Name OrderID Product
1 Anna NULL NULL
2 Bernd 101 Book
3 Clara NULL NULL

Created 1 Day 7 Hours ago
Database Databases Explicit join Implicit join Inner Join MySQL Outer Join PostgreSQL RDBMS Relational Database Relational Databases SQL SQLite Strategies Structured Query Language - SQL

Leave a Comment Cancel Reply
* Required Field