What is the difference between INNER JOIN and OUTER JOIN?
INNER JOIN vs. OUTER JOIN: Understanding SQL Data Retrieval

Explore the fundamental differences between INNER JOIN and OUTER JOIN in SQL, and learn when to use each to effectively combine data from multiple tables.
In the world of relational databases, combining data from multiple tables is a common and essential task. SQL JOIN clauses are the primary mechanism for achieving this, allowing you to link rows from two or more tables based on related columns. While there are several types of JOINs, INNER JOIN
and OUTER JOIN
(which includes LEFT OUTER JOIN
, RIGHT OUTER JOIN
, and FULL OUTER JOIN
) are the most frequently used and often confused. Understanding their distinctions is crucial for writing accurate and efficient SQL queries.
What is an INNER JOIN?
An INNER JOIN
returns only the rows that have matching values in both tables being joined. If a row in one table does not have a corresponding match in the other table based on the join condition, it is excluded from the result set. Think of it as finding the intersection of two sets of data.
flowchart LR TableA[Table A] -- Matching Rows --> Intersection((INNER JOIN Result)) -- Matching Rows --> TableB[Table B]
Conceptual representation of an INNER JOIN, showing only the intersection of matching rows.
SELECT
Orders.OrderID,
Customers.CustomerName
FROM
Orders
INNER JOIN
Customers ON Orders.CustomerID = Customers.CustomerID;
Example of an INNER JOIN to retrieve orders with their corresponding customer names.
INNER JOIN
when you only care about records that exist in both tables. For instance, if you want to see orders that definitely have a customer, and customers that definitely have an order.What is an OUTER JOIN?
Unlike INNER JOIN
, OUTER JOIN
s are designed to include rows that do not have a match in the other table. There are three main types of OUTER JOIN
s, each with a slightly different behavior regarding unmatched rows:
LEFT OUTER JOIN (or LEFT JOIN)
A LEFT OUTER JOIN
returns all rows from the left table, and the matching rows from the right table. If there is no match for a row in the left table, the columns from the right table will contain NULL
values. The OUTER
keyword is optional and often omitted, making it simply LEFT JOIN
.
flowchart LR TableA[Table A] -- All Rows --> LeftResult((LEFT JOIN Result)) -- Matching Rows --> TableB[Table B] LeftResult -- Unmatched Rows (NULLs) --> TableA
Conceptual representation of a LEFT JOIN, including all rows from the left table and matches from the right.
SELECT
Customers.CustomerName,
Orders.OrderID
FROM
Customers
LEFT JOIN
Orders ON Customers.CustomerID = Orders.CustomerID;
Example of a LEFT JOIN to list all customers and their orders, including customers who have placed no orders (OrderID will be NULL).
RIGHT OUTER JOIN (or RIGHT JOIN)
A RIGHT OUTER JOIN
is the mirror image of a LEFT JOIN
. It returns all rows from the right table, and the matching rows from the left table. If there is no match for a row in the right table, the columns from the left table will contain NULL
values. Similar to LEFT JOIN
, OUTER
is optional.
SELECT
Customers.CustomerName,
Orders.OrderID
FROM
Customers
RIGHT JOIN
Orders ON Customers.CustomerID = Orders.CustomerID;
Example of a RIGHT JOIN to list all orders and their customer names, including orders that might not have a corresponding customer (CustomerName will be NULL).
FULL OUTER JOIN (or FULL JOIN)
A FULL OUTER JOIN
returns all rows when there is a match in either the left or the right table. This means it includes all rows from both tables, filling in NULL
s for columns where there is no match in the other table. It's essentially the union of a LEFT JOIN
and a RIGHT JOIN
.
flowchart LR TableA[Table A] -- All Rows --> FullResult((FULL JOIN Result)) -- All Rows --> TableB[Table B] FullResult -- Unmatched Rows (NULLs) --> TableA FullResult -- Unmatched Rows (NULLs) --> TableB
Conceptual representation of a FULL JOIN, including all rows from both tables, with NULLs for unmatched data.
SELECT
Customers.CustomerName,
Orders.OrderID
FROM
Customers
FULL OUTER JOIN
Orders ON Customers.CustomerID = Orders.CustomerID;
Example of a FULL OUTER JOIN to list all customers and all orders, showing NULLs where no match exists in the other table.
FULL OUTER JOIN
as it can produce very large result sets and may be less performant than INNER
or LEFT/RIGHT JOIN
s if not used judiciously. Not all database systems support FULL OUTER JOIN
(e.g., MySQL does not directly, requiring a UNION
of LEFT
and RIGHT
joins).Key Differences and When to Use Each
The choice between INNER JOIN
and OUTER JOIN
hinges entirely on your data retrieval requirements. Do you need only the common records, or do you need to include records that might not have a match in the other table?

Visual comparison of INNER, LEFT, RIGHT, and FULL JOIN results using Venn diagrams.
Here's a summary of their primary use cases:
INNER JOIN
: Use when you want to retrieve records that exist in both tables. This is the most common type of join and is suitable when you need to combine related data where a match is expected and required.LEFT JOIN
: Use when you want to retrieve all records from the left table, along with any matching records from the right table. If there's no match on the right, the right-side columns will beNULL
. This is useful for finding records in the left table that don't have a match in the right table (by filteringWHERE RightTable.Column IS NULL
).RIGHT JOIN
: Use when you want to retrieve all records from the right table, along with any matching records from the left table. If there's no match on the left, the left-side columns will beNULL
. Less common thanLEFT JOIN
as you can often achieve the same result by swapping table order and usingLEFT JOIN
.FULL OUTER JOIN
: Use when you want to retrieve all records from both tables, regardless of whether they have a match in the other table. This is useful for comprehensive analysis where you need to see all data points, even if they are incomplete in one table.