Join conditons generally asked during interviews

So everybody know joins in SQL but there are some game of null and repeated values which people generally miss so here i am demonstrating all those condition. we’ll go step by step,lets create tables then play with joins. Before running any query think twice what will be the output.

Create table JoinA (col int),Create table JoinB (col int)

Insert into JoinA values(1)
Insert into JoinA values(1)
Insert into JoinA values(1)
Insert into JoinA values(2)
Insert into JoinA values(2)
Insert into JoinA values(null)

Select * from JoinA

Insert into JoinB values (1)
Insert into JoinB values (1)
Insert into JoinB values (2)
Insert into JoinB values (2)
Insert into JoinB values (2)
Insert into JoinB values (null)
Insert into JoinB values (null)

Select * from JoinB

–Inner Join

Select * From JoinA Join JoinB On JoinA.col=JoinB.col 

–Left Join

Select * From JoinA Left Join JoinB On JoinA.col=JoinB.col

–Right Join

Select * From JoinB Right Join JoinA On JoinB.col=JoinA.col 

–Outer Join

Select * From JoinA Full Join JoinB On JoinA.col=JoinB.col

if you people want to add into this please welcome.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s