At the early stages, it’s confusing what left and right join is actually all about, and which to apply where and what will be the outcome for the same.
Today I will try to show with an example what the difference between left and right join actually is with practical examples.
Create two tables and we call it A and B. Both will have two fields, i.e., id and name.
- create table A(IDint, Name varchar (10))
- GO
- create table B(IDint, Name varchar (10))

We have two records in A and three records in B.
Left Join
Fetches data from the left table no matter that data is there in the right table. If data is there in the right table it will show the same, else it will show the null values.
Right Join
Fetches the data from the right table no matterthat data is there in the left table. If data is there in the left table, it will show the same, else it will show the null values.

Let us see the result of the queries:
- Query:
Output:- Select * FROM A leftJOIN B ON A.id = B.id
Description: We have two records in table 1, so left join will match the same in the table 2, and hence it found the matching records in table two.
- Query:
Output:- SELECT * FROM B RightJOIN A on B.id = A.id

Description: Here the output for both the queries is the same. In the second query we are doing right join with table A and table A is having 2 records.
- Query:
Output:- Select*from A rightjoin B on A.id = B.id

Description: In this query we are doing right join with table B which is having 3 records. So in the output it showed the record 3rd from table B. But in table A no matching records were found, so it showed null values for the same.
- Query:Output:
- select * from B LEFTjoin A on A.id = B.id

Description: In this query we are doing left join with table B which is having 3 records. So in the output it showed the record 3rd from table B. But in table A no matching records were found, so it showed null values for the same.


SubashPosted Jul 4, 2016, 4:51 AM EDT
Simple and Good
Nishant MittalPosted Jan 23, 2016, 7:44 PM EST
Thanks
Santhakumar MunuswamyPosted Jan 22, 2016, 9:19 PM EST
Thanks for nice share
Nishant MittalPosted Jan 22, 2016, 6:34 AM EST
Thanks Jaco
Jaco ZwartsPosted Jan 22, 2016, 6:16 AM EST
Thank you so much helping me with my studies!, really good explanation
Nishant MittalPosted Jan 21, 2016, 2:04 AM EST
Thanks Anil
Anil Kumar MurmuPosted Jan 21, 2016, 1:58 AM EST
good explanation..
Nishant MittalPosted Jan 20, 2016, 6:24 PM EST
Thanks Guys
Raja TPosted Jan 20, 2016, 5:52 PM EST
Nice, Thanks for sharing
Vipul MalhotraPosted Jan 20, 2016, 12:49 AM EST
nice article
Nishant MittalPosted Jan 20, 2016, 12:46 AM EST
Thanks Bro..
Pankaj Kumar ChoudharyTOP 100Posted Jan 20, 2016, 12:33 AM EST
Nice Explain Sir..
Nishant MittalPosted Jan 20, 2016, 12:15 AM EST
Thanks Guys ...
Nanddeep NachanTOP 100Posted Jan 20, 2016, 12:02 AM EST
Nice share
Yashwant VishwakarmaPosted Jan 19, 2016, 11:23 PM EST
Nice work, thank for sharing
Shubham KumarPosted Jan 19, 2016, 10:47 PM EST
nice