Left Outer Join
The concept of Left Outer Join is similar and same to the Left Join, and both these terms are interchangeably used. The keyword used here is “Outer“, which is optional and also doesn’t impact the result.
Let’s see the syntax of Left Outer Join:
Syntax
SELECT columns
FROM left_table
LEFT OUTER JOIN right_table ON
join_condition;
Example:
Let’s consider the same tables used in the above Left Join Example:
Query for Left Outer Join
SELECT Customer_Data.customer_id, Customer_Data.customer_name,
Orders_Data.order_id, Orders_Data.order_date FROM Customers_Data
LEFT OUTER JOIN Orders ON
Customers_Data.customer_id = Orders_Data.customer_id;
Result/Output
customer_id |
customer_name |
order_id |
order_date |
---|---|---|---|
1 |
Gaurav |
1 |
2023-01-23 |
1 |
Gaurav |
2 |
2023-02-03 |
2 |
Anjali |
NULL |
NULL |
3 |
Ramesh |
3 |
2023-03-05 |
4 |
NULL |
NULL |
NULL |
Explanation
In the above example, non-matching records from the right table (“Orders_Data“) are included, and NULL values are shown for the right table columns. Thus, the customer with ‘customer_id‘ 4 in the Orders_Data table, which doesn’t have a matching record in the Customer_Data table is also included in the result set and the NULL values are shown, which was not displayed in the Left Join condition.
Difference Between Left Join and Left Outer Join
Database in any computer system is the collection of structured or unstructured data that can be used to perform various options like creation, deletion, etc. This database is managed by a special language known as SQL. In SQL language there are different joins that are used to assemble rows from two or more tables from the related column. Some of the joins are Inner Join, Left Join, and Right Join. In this article, we will explore the concepts with examples of Left Join and Left Outer Join. Along with this, we will also go through their main differences.