Friday, 23 January 2015

Types of Join in SQL Server||Different Types of SQL Joins||Join in SQL - Inner, Outer, Left, Right Join


Joins in Sql Server

Table 1:











 Table 2













Inner Join :-

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.

select * from emp1
JOIN
emp2
on emp1.eid=emp2.eid






Left Outer Join:-
The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.

Query for Left Outer Join:-
select * from emp1
left outer join
emp2
on emp1.eid=emp2.eid








Right Outer Join:-
The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.

Query for Right Outer Join:-













SQL FULL OUTER JOIN
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2).
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.

Query for FULL OUTER JOIN :-

select * from emp1
FULL OUTER JOIN
emp2
on emp1.eid=emp2.eid




Cross join:-
SQL CROSS JOIN will return all records where each row from the first table is combined with each row from the second table. Which also mean CROSS JOIN returns the Cartesian product of the sets of rows from the joined tables.


SELECT * FROM emp1 CROSS JOIN emp2





Write a query to display from table1 and table2 records?
Table 1



Table2



Sql query to join two tables are:-
select emp1.eid,emp1.ename,emp1.esal,emp2.eadd,emp2.ephone from emp1 join emp2 on

emp1.eid=emp2.eid
























0 comments:

Post a Comment