Showing posts with label types of join in sql. Show all posts
Showing posts with label types of join in sql. Show all posts

Thursday, July 28, 2016

Joins in SQL server




In SQL joins are used to combine the data from two or more tables, it based on the relationship between columns in tables. Join is used to combine field from two tables by using values common to each.
The Example of Joins in given below:
Firstly we create two tables name emp and emp1
emp table – 

emp1 table -



Now we join these table in our select statement as following:


select id,name,dept from emp,emp1
where emp.Salary=emp1.salary

Output -  


Types of Joins:
Inner Join – return those rows who is match in both tables.
Left Join – It return all rows from left table ,if there is no row matches in the right table.
Right Join – it return all rows from right table, if there is no row matches in the left table.
Full Join – It returns rows when there is a match in one of the tables.
Self Join – Self join is used to join the table by itself.
Cartesian Join – it return Cartesian product of records from two or more joined tables.
                                                              Author - Sachin Pathak