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 |
An explicit join is a clear and direct way to define a join in an SQL query, where the type of join (such as INNER JOIN
, LEFT JOIN
, RIGHT JOIN
, or FULL OUTER JOIN
) is explicitly stated.
SELECT *
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
This makes it clear:
Which tables are being joined (customers
, orders
)
What kind of join is used (INNER JOIN
)
What the join condition is (ON customers.customer_id = orders.customer_id
)
An implicit join is the older style, using a comma in the FROM
clause, and putting the join condition in the WHERE
clause:
SELECT *
FROM customers, orders
WHERE customers.customer_id = orders.customer_id;
This works the same, but it's less clear and not ideal for complex queries.
More readable and structured, especially with multiple tables
Clear separation of join conditions (ON
) and filter conditions (WHERE
)
Recommended in modern SQL development
An implicit join is a way of joining tables in SQL without using the JOIN
keyword explicitly. Instead, the join is expressed using the WHERE
clause.
SELECT *
FROM customers, orders
WHERE customers.customer_id = orders.customer_id;
In this example, the tables customers
and orders
are joined using a condition in the WHERE
clause.
SELECT *
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id;
Aspect | Implicit Join | Explicit Join |
---|---|---|
Syntax | Tables separated by commas, joined via WHERE |
Uses JOIN and ON |
Readability | Less readable in complex queries | More structured and readable |
Error-proneness | Higher (e.g., accidental cross joins) | Lower, as join conditions are clearer |
ANSI-92 compliance | Not compliant | Fully compliant |
It was common in older SQL code, but explicit joins are recommended today, as they are clearer, easier to maintain, and less error-prone, especially in complex queries involving multiple tables.