In this post, we will understand the difference between left outer join, right outer join, and full 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.
SELECT [column_1, column_2, ….] FROM table_1 LEFT OUTER JOIN table_2 ON table_1.matching_column = table_2.matching_column
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.
SELECT [column_1, column_2, ….] FROM table_1 RIGHT OUTER JOIN table_2 ON table_1.matching_column = table_2.matching_column
It fetches all rows from both tables.
It is similar to performing an "inner join all unmatched rows in the left table all unmatched rows in the right table".
No data will be lost in this operation.
SELECT [column_1, column_2, ….] FROM table_1 FULL OUTER JOIN table_2 ON table_1.matching_column = table_2.matching_column
The above is the detailed content of Difference between left, right and full outer join. For more information, please follow other related articles on the PHP Chinese website!