Monthly Archives: September 2015

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.