You are on page 1of 4

Single row subquery: Subquery will return a

single value

Select * from emp where salary > (select


max(salary) from emp where did=10);

Multirow sub query

Select * from emp where salary>(select


avg(salary) from emp group by did);
Eid Ename did salary jid
100 a 10 10000 j1
101 b 10 12000 j1
102 c 20 2000 j2
103 d 20 8000 j3
104 e 10 14000 j4
105 f 30 5000 j3

did avg(salary)
10 12000
20 5000
30 5000
Select * from emp where salary in (select
avg(salary) from emp group by did);
105 f 30 5000 j3

Select * from emp where salary > all (select


avg(salary) from emp group by did);
104 e 10 14000 j4

Select * from emp where salary <all (select


avg(salary) from emp group by did);
102 c 20 2000 j2
Select * from emp where salary <any (select
avg(salary) from emp group by did);
Eid Ename did salary jid
100 a 10 10000 j1
102 c 20 2000 j2
103 d 20 8000 j3
105 f 30 5000 j3

Select * from emp where salary >any (select


avg(salary) from emp group by did);
Eid Ename did salary jid
100 a 10 10000 j1
101 b 10 12000 j1
103 d 20 8000 j3
104 e 10 14000 j4

In the above query, subquery is returning


more than one value.These type of subquery
is called as multirow subquery. We have to
use multirow subquery operators.
IN(multiple values can be compared at a time)
ANY
ALL
>all--àgreater than the maximum
<all---àless than the minimum
>anyàgreater than the minimum
<anyàless than the maximum

You might also like