Joins In Sql Server:
******************
1. Cross join
2. Inner join
3. Outer join
Left Outer join
Right Outer join
Full outer join
4. Self join
Eg:
1. Cross join
************
select * from emp
select * from dept
select empid, location from emp cross join dept
2. Inner join
***********
select empid, ename , a.deptno , location from emp a inner join dept b on
a.deptno = b.deptno
3. Outer join
************
Left Outer Join
select empid, a.deptno ,salary, location from emp a left outer join dept b on
a.deptno = b.deptno
Right Outer Join
select empid, a.deptno ,salary, location from emp a right outer join dept b on
a.deptno = b.deptno
Full Outer Join
select empid, a.deptno ,salary, location from emp a full outer join dept b on
a.deptno = b.deptno
4. Self Join
**********
select a.empid, a.deptno , a.salary from emp a join emp b on
a.empid = b.empid
select a.empid, a.deptno , a.salary , a.mgrid from emp a , emp b where
a.empid = b.mgrid
17.3.08
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment