Tuesday, 14 February 2012

Multi Row Sub Query

=>    If Inner query returns more than one column then Sub Query is called "Multi Row Sub Query".
=>    No of Columns returned by Inner Query = No of columns used in where clause of Outer Query.
=>    Corresponding columns datatype must be same.

    Syntax:
    =>    Where (col1, col2) OP ( Select column1, column2 from tableName );

=>    OP can be { =, IN, NOT IN }

    Examples:
    1. Display emp records earning max sal in their dept ?
    =>    Select * from emp where (deptno, sal) in ( select deptno, MAX(sal) from emp GROUP BY deptno);

No comments:

Post a Comment