=> Equi JOIN returns only matching records but doesn't return un-matched records.
=> To get the un-matched records also we need to perform Outer Join.
=> Outer join is of 3 types:
(a) Left Outer
(b) Right Outer
(c) Full Outer
a) Left Outer Join:
=> It returns all the records from Left side table and matching records from Right side table.
Syntax:
=> Select <collist> from <tablelist> where <cond1> = <cond2> (+)
=> Select <collist> from <table1> LEFT OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the employee records and their respective dept names ?
=> Select e.ename, d.dname from emp e, dept d where e.deptno = d.deptno (+);
(or)
=> Select e.ename, d.dname from emp e LEFT OUTER JOIN dept d ON ( e.deptno = d.deptno )
(or)
=> Select e.ename , d.dname from emp e LEFT OUTER JOIN dept d USING( deptno );
b) Right Outer Join:
=> It returns all the records Right side table and matching records from Left side table.
Syntax:
=> Select <collist> from <tablelist> where <cond1> (+)= <cond2>
=> Select <collist> from <table1> RIGHT OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the dept records and their respective employees ?
=> Select d.dname,e.ename from dept d, emp e where d.deptno (+)= e.deptno ;
(or)
=> Select d.dname,e.ename from dept d RIGHT OUTER JOIN emp e ON ( d.deptno = e.deptno )
(or)
=> Select d.dname,e.ename from dept d RIGHT OUTER JOIN emp e USING( deptno )
c) Full Outer Join:
=> It return all records from both the tables.
=> It doesn't support NON-ASCII JOIN.
Syntax:
=> Select <collist> from <table1> FULL OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the employee records and dept records.
=> Select e.ename, d.dname from emp e
FULL OUTER JOIN dept d USING( deptno );
=> To get the un-matched records also we need to perform Outer Join.
=> Outer join is of 3 types:
(a) Left Outer
(b) Right Outer
(c) Full Outer
a) Left Outer Join:
=> It returns all the records from Left side table and matching records from Right side table.
Syntax:
=> Select <collist> from <tablelist> where <cond1> = <cond2> (+)
=> Select <collist> from <table1> LEFT OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the employee records and their respective dept names ?
=> Select e.ename, d.dname from emp e, dept d where e.deptno = d.deptno (+);
(or)
=> Select e.ename, d.dname from emp e LEFT OUTER JOIN dept d ON ( e.deptno = d.deptno )
(or)
=> Select e.ename , d.dname from emp e LEFT OUTER JOIN dept d USING( deptno );
b) Right Outer Join:
=> It returns all the records Right side table and matching records from Left side table.
Syntax:
=> Select <collist> from <tablelist> where <cond1> (+)= <cond2>
=> Select <collist> from <table1> RIGHT OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the dept records and their respective employees ?
=> Select d.dname,e.ename from dept d, emp e where d.deptno (+)= e.deptno ;
(or)
=> Select d.dname,e.ename from dept d RIGHT OUTER JOIN emp e ON ( d.deptno = e.deptno )
(or)
=> Select d.dname,e.ename from dept d RIGHT OUTER JOIN emp e USING( deptno )
c) Full Outer Join:
=> It return all records from both the tables.
=> It doesn't support NON-ASCII JOIN.
Syntax:
=> Select <collist> from <table1> FULL OUTER JOIN <table2> ON <join condition>
Examples:
1. Display all the employee records and dept records.
=> Select e.ename, d.dname from emp e
FULL OUTER JOIN dept d USING( deptno );
No comments:
Post a Comment