Monday, 13 February 2012

EQUI JOIN or INNER JOIN

    => Use EQUI join when two or more tables are sharing the common column.

    Syntax:
    =>    Select <collist> from <tablelist> where <join_condition>
    =>    Select <collist> from <table 1> JOIN  <table 2> ON <join_condition>
    =>    Select <collist> from <table 1> JOIN  <table 2> USING (common_column)
            -- In USING() column name must be same in both tables.

    Examples:

    1. Display employee names and their respective dept name ?
    =>    Select e.ename , d.dname from emp e, dept d where e.deptno = d.deptno;
            (or)
    =>    Select e.ename , d.dname from emp e JOIN dept d ON e.deptno = d.deptno;
            (or)
    =>    Select e.ename , d.dname from emp e JOIN dept d USING( deptno );

    2. Display names of the employees who are working in Newyork.
    =>    Select e.ename, d.loc from emp e, dept d where e.deptno = d.deptno and d.loc = 'NEWYORK';
            (or)
    =>    Select e.ename , d.loc from emp e JOIN dept d ON e.deptno = d.deptno AND d.loc = 'NEWYORK';
            (or)
    =>    Select e.ename , d.loc from emp e JOIN dept d USING( deptno ) where d.loc = 'NEWYORK';

No comments:

Post a Comment