Tuesday, 14 February 2012

Scalar Queries

=>    Sub Queries follows select clause are called Sub Queries.
=>    A scalar query 1 value per row.

    Syntax:
    =>    Select (subQuery1), (subQuery2), .... From tableName;

=>    Sub Query can be used in
    a)    Where
    b)    From
    c)    Select etc..

    Examples:
    1. Display the no of records in Emp and Dept ?
    =>    Select ( select count(*) from emp ) as emp,
            ( select count(*) from dept ) as dept
        from dual;
   
    2. Display the following report ?
        ename    sal    deptno    dept_sumsal
   
    =>    Select ename, sal, deptno, (select sum(sal) from emp e where e.deptno = deptno) as dept_sumsal from emp;

No comments:

Post a Comment