Joins are typically used to combine two different datasets on the common items. Let's look into each type of join with an example.
An inner join combines two datasets using common columns and discards all the unmatched rows.
A left join combines the current dataset with another dataset using common columns, and discards all unmatched rows from the other dataset.
Left join can be represented as:
Let's take the example of the following datasets:
Orders daaset
Customers dataset
Left join has combined the rows of the two datasets that shared values in the Order ID column. The unmatched values were only discarded from the Customers dataset.
Right join
A right join combines the current dataset with another dataset using common columns and discards all unmatched rows from the current dataset.
Right join can be represented as:
Let's take the example of the following datasets:
Orders dataset
Customers dataset
Right join has combined the rows of the two datasets that shared values in the Order ID column. The unmatched values were only discarded from the Orders dataset.
Outer join
Outer join uses common columns to combine two datasets, including the unmatched rows from both the datasets. An outer join can be represented as:
Let's take the example of the following datasets.
Orders dataset
Customers dataset
Outer join has combined the rows of the two datasets that shared values in the Order ID column. The unmatched values are kept from both Orders and Customers datasets.
SEE ALSO