Difference Between Left, Right and Full Outer Join

MySQLDatabaseData Storage

In this post, we will understand the difference between left outer join, right outer join, and full outer join.

Left Outer Join

It fetches all the rows from the table on the left.

It is same as ‘Inner Join + all the unmatched rows from the left table’.

The data that isn’t matched on the right table is lost.

Example:

SELECT [column_1, column_2, ….]
FROM table_1
LEFT OUTER JOIN table_2 ON
table_1.matching_column = table_2.matching_column

Right Outer Join

It fetches all the rows of the table on the right.

It is similar to performing ‘Inner Join + all of the unmatched rows from the right table’.

The unmatched data from the left table is lost.

Example:

SELECT [column_1, column_2, ….]
FROM table_1
RIGHT OUTER JOIN table_2 ON
table_1.matching_column = table_2.matching_column

Full Outer Join

It fetches all of the rows from both the tables.

It is similar to performing ‘Inner Join +all of the unmatched rows from the left table + all the unmatched rows from the right table’.

No data is lost during this operation.

Example:

SELECT [column_1, column_2, ….]
FROM table_1
FULL OUTER JOIN table_2 ON
table_1.matching_column = table_2.matching_column
raja
Published on 25-Mar-2021 06:32:09
Advertisements