Types of Joins in SQL
We have three types of Joins in sql.
They are
1. Inner join
2. Outer join
3. Cross join
1. Inner join:
Inner join is the default type of join, it will producesses the result set, which contains matched rows only.
Syntax: select * from table1<innerjoin>table2
Here noneed of specifying innerjoin. Simply we can specify Join also.
Syntax: select * from table1<join>table2
2. Outer join:
Outer join produces the results, which contains matched rows and unmatched rows.
Outer join is further classified as three types.They are
A. left outer join
B. right outer join
C. full outer join.
A. Left outer join:
Left outer join producesses the results, which contains all the rows from left table and matched rows from right table.
Syntax: select * from table1<leftouterjoin>table2
B. Right outer join:
Right outer join producesses the resultset, which contains all the rows from right table and matched rows from left table.
Syntax:select * from table1<right outer join>table2
C. Full outer join:
Full outer join producesses the resultset, which contains all the rows from left table and all the rows from right table.
Syntax:select * from table1<fullouterjoin>table2
3.Cross join:
A join without having any condition is known as cross join, in cross join every row in first table is joins with every row in second table. Cross join is nothing but cortizion product.
Syntax: select * from table1<cross join>table2
Self join:
A join joins withitself is called self join working with self joins we use alias tables.
No comments:
Post a Comment