![]() |
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. Left JoinLeft Join in SQL language is used to return all the data or records from the left table and the matching data or records from the right table. In the scenario, where there is no match, then the join still consists of the rows from the left table and displays the NULL values for the columns of the right table. In the context of the query, below is the syntax of the Left Join. Syntax
Now, let’s understand the Left Join through a simple example: Example: 1. Customer_Data Table:
2. Orders_Data Table:
Query for Left JoinSELECT Customer_Data.customer_id, Customer_Data.customer_name, Result/Output
ExplanationIn the above example. Left Join includes all rows from the left table (Customer_Data) and matched them with the corresponding rows of the right table (Orders_Data). Here, Customer Gaurav has 2 orders, Anjali has no orders (NULL), and Ramesh has 1 order. Left Outer JoinThe 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
Example: Let’s consider the same tables used in the above Left Join Example: Query for Left Outer JoinSELECT Customer_Data.customer_id, Customer_Data.customer_name, Result/Output
ExplanationIn 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
FAQs on Left Join and Left Outer Join1. When should we use a Left Join?
2. What are the benefits of using Left Join?
3. Explain the results of Left Outer Join.
4. Can we use the ORDER BY clause along with Left Outer Join?
|
Reffered: https://www.geeksforgeeks.org
DBMS |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |