Left Join in SQL | SQL Server Left Join

In Left Join in SQL articles, we learn in detail with an example and understand the difference between SQL LEFT Join and Left Outer Join.
The Left Join in SQL returns all records from the left table(table1) and the also matched records from the right table (table2). the results will become NULL from the right side (table2), if there no records will be matched.
In some databases, LEFT JOIN is called LEFT OUTER JOIN.

.
Note:
In some databases, The LEFT JOIN is also called the LEFT OUTER JOIN.
The LEFT JOIN in SQL command returns all rows from the left table (table1) and the matching rows from the right table (table2). The result is NULL from the right side if there is no match found from the right table.

Syntax:

Left JOIN IN SQL
In this syntax, Table1 and Table2 are the left tables and right tables.

For each row from the left table (table1), the query compares it with all the rows from the Right table (table2).
Therefore, If a pair of rows causes the join predicate to evaluate to TRUE, the column values from these rows will be combined to form a new row which then included in the result set.

Furthermore, If a row from the left table (Table1) does not have any matching row from the right table (table2), then the query combines column values of the row from the table1 with NULL for each column values from the table2.

as a result, In short, you can understand that the LEFT OUTER JOIN clause returns all rows from the left table (Table1) and matching rows or NULL values from the right table (table2).

Example: Left Join in SQL

Let’s consider the following two demo tables,

Table1: Customers

CustomerID CustomerName Age Address Salary
101 James Hudson 32 Paris 3000
102 Noah Charles 35 Belgium 4500
103 William Josiah 31 Argentina 3800
104 Liam Isaiah 34 France 3400
105 Oliver Christian 39 Germany 4100
106 Elijah Connor 42 Mannheim 4300
107 Benjamin Hunter 44 Argentina 4700
108 Elijah Connor 51 Honduras 5500
109 Alexander Landon 52 Strasbourg 5700
110 Ethan Adrian 30 Monrovia 7600
111 Logan Aaron 24 Liberia 7500
112 Michael Nolan 25 Rome 7100
113 Jacob Jonathan 22 Mannheim 7300
114 Henry Easton 27 Guyana 3400
115 Sebastian Colton 28 Tegucigalpa 3700
116 Dylan Santiago 38 México 5100
117 Gabriel Roman 52 Brussels 6100
118 Anthony Xavier 25 Monrovia 7700
119 Theodore Axel 23 Strasbourg 8100
120 Thomas sawyer 27 Buenos Aires 5700

Table2: OrderDetails

OrderID CustomerID OrderDate Amount
11 102 2015-01-11 2100
15 106 2015-01-14 3400
13 108 2015-01-17 1500
12 111 2015-01-22 1600
19 115 2015-01-25 1900
18 108 2015-01-27 1200
16 119 2015-03-17 2000

Left Join in SQL: Case-I

Now, let us see the Left join SQL, therefore these two tables using the JOIN as follows.
Therefore, In this case, we consider the Customers table is table1 and OrderDetails table considers the table2, both table are connected to each other. furthermore, let’s see the result:


Example output

.
Note:
Therefore, as a result, you can see that join returns all the values from the left table, plus matched values from the right table or NULL in case of no matching join predicate.

Left Join in SQL: Case-II

Now, let us see the Left join SQL, therefore these two tables using the JOIN as follows.
Therefore, In this case, we consider the OrderDetails table is table1 and Customers table considers the table2, both table are connected to each other. furthermore, let’s see the result:


Output second case

.
Note:
Therefore, as a result, you can see that join returns all the values from the left table, plus matched values from the right table or NULL in case of no matching join predicate.

Difference Between SQL Left Join and SQL Left Outer Join

There is actually no difference between a SQL left join and a SQL left outer join, In some databases, therefore, both of them refer to the similar operation in SQL.
Let’s know the difference between through example:-

Sample Table: MedicalStore

StoreID StoreName City
11 Healthy Floyds Strasbourg
12 Healthy Pharmacy Italy
13 Generation Pharmacy London
14 Medilane Pharmacy France
15 Center Pharmacy Argentina
16 Arrow Pharmacy Mexico
17 Windsor Pharmacy Paris
18 Downtown Pharmacy Georgetown
19 NuCare Pharmacy Germany
20 Thriftway Pharmacy Monrovia

Sample Table: Medicine

ItemID MedicineName ItemUnit StoreID
2 Acyclovir Piece 15
5 Alendronate Piece 13
1 Amitriptyline Piece 11
3 Amlodipine Piece 14
6 Melphalan Piece 12
4 Bleomycin Piece 13
9 Bosentan Piece 17
7 Busulfan Piece 16
8 Celecoxib Piece 15
10 Cisplatin Piece 12
12 Cytarabine Piece 19
11 Hydroxyurea Piece NULL

Therefore, you will that the very last row in the MedicalStore table, the Store ID does not exist in the Medicine table. Also, you can notice that the very last row in the Medicine table the value of Store ID is NULL and does not exist in the MedicalStore table. so, these facts will prove to be significant of the left join in SQL.
Therefore, the given below the SQL statement without using “outer” with “left join”.


Difference Between Left Join and Left Outer Join
Therefore, when we running the SQL Statement with the "outer" keyword, would give us the exact same results as per the SQL without the “outer”. therefore, the following below SQL statement is with "outer" with "left join".

Therefore, left outer join or left join retains all of the rows of the left table MedicalStore, regardless of whether there is a row that matches on the right table Medicine. Here is the output below, which is the same output as per the above SQL Statement.

Difference Between Left Join and Left Outer Join

Conclusion:

Furthermore, Now you should have a good understanding of how the LEFT JOIN SQL clause works and know how to apply the LEFT JOIN clause to query data from multiple tables. I hope you will enjoy it!, if have any query Email us, I will try to reach.