Saturday 19 July 2014

SQL Join


Inner Join
Outer Join- Left Outer
Outer Join- Right Outer
Outer Join- Full Outer
Cross Join
>>Inner Join
If i take 2 tables, it will return common Data.
Ex: Select * from Table1
Inner Join Table2
on
Table1.ID=Table2.ID
>>Left Outer Join
Common data and All data from left table
Ex: Select * from Table1 Left Outer Join Table2
on
Table1.Id=Table2.Id
What is left table?
Ans) In the above ex. we have 2 tables, Table1 and Table2.
The table name which is available before "Left Outer Join" is Left Table
>>Right outer join
Common data and All data from right table
Ex: Select * from Table1 Right Outer Join Table2
on
Table1.Id=Table2.Id
What is right table?
Ans) In the above ex. we have 2 tables, Table1 and Table2.
The table name which is available before "Right Outer Join" is right Table
>>Full Outer Join
All data from both table
Ex: Select * from Table1 Full Outer Join Table2
on
Table1.Id=Table2.Id
>>Cross Join
If we have 2 table. If table1 is having 5 and table2 6 records are there, then out put will be 30 records.
Ex: Select * from Table1 Cross Join Table2
In MDX we will use Cross join.