Tuesday, 14 February 2012

Inline Views

=> Sub Query following From clause is called "Inline View".
=> The result of the Sub Query acts as a table for Outer Query.

=> Inline views are used in the following scenarios:
    (i)    To use column alias in where clause.
    (ii)    To use Window functions.
    (iii)    To use result of one process in another process.

    Syntax:
    =>    Select * from <SubQuery> [ where condition ];

    Examples:
    =>    Select * from ( Select ename, sal from emp e );

    1. Display 5th record from emp ?
    =>    Select * from ( select rownum, empno, ename, sal from emp) where rownum = 5;

    2. Get the top 3 max salaries from emp ?
    =>    Select * from ( select rownum, empno, ename, sal from emp order by sal desc) where rownum <4;

No comments:

Post a Comment