SCALAR QUERIES  :-

subqueries follows select clause are called “scalar queries”

Syntax  :-

Select (select statement) , (select statement) From<tabname>

Example  :-

Select (select max(sal) from emp where deptno =10) D10, (select max(sal) from emp where deptno=20) D20, (select max(sal) from emp where deptno =30) D30

  • Output:-        D10          D20               D30
  •                          6000       5000           4000

Display max salary of top3 & top3 of minimum salary

Select (select distinct sal from (select ename, sal, dense_rank ( ) over (order by sal desc) rnk from emp) where rnk<=3) max, (select distinct sal from (select ename, sal, dense_rank  ( ) over(order by sal) rnk from emp) where rnk<=3) min

Output →                                   Max                              Min        

                                                        3000                           9000

                                                         2500                          800

                                                         1500                          700