Friday, August 19, 2016

What is a left join?


The left join use for just come the whole  information  of left table only the right table data come with the result of matching .If there no matching there come Null .


                                                                        
Customer Table                                
Customer ID
Name
Phone  Number
1
Erfan
01672
2
Enan
01822
3
Ali
01722
Order Table 
OrderID
Quantity
CustomerID
123
1
1
321
2
2
222
4
4













Query:                
SELECT Customer.Name,Order.OrderID              
From Customer
Left  Join Order 
on  Customer.CustomerID = Order.CustomerID



Result:

Name
OrderID
Erfan
123
Enan
321
Ali
Null

  

                                                                        




Left  Table all data come but right side only matching data come . How we decide which table left ,this is simple when we write sql left side table name is left .For decision you can think your hand direction also.

No comments:

Post a Comment