Subquery
Subquery
(iii). Subqueries can be placed in various parts of SQL statements such select
clause, from clause, where clause
select * from employees where salary > (select salary from employees where
first_name='Neena');
Types:
Relational operators
=
!=
>
>=
<
<=
select * from employees where salary > (select salary from employees where
first_name='Neena');
select * from employees where salary = (select salary from employees where
first_name='Neena');
Relational operators
IN
NOT IN
ALL ------ <all, >all, >=all, <=all
ANY ------ <any, >any, >=any, <=any
select * from employees where salary > (select salary from employees where
department_id=30);
select * from employees where salary IN (select salary from employees where
department_id=30);
select * from employees where salary >all (select salary from employees where
department_id=30);
select * from employees where salary >all (select salary from employees where
department_id=30);
select * from employees where salary < all (select salary from employees where
department_id=30);
select first_name,salary from employees where salary <any (select salary from
employees where first_name='Den');
Scalar Subquery:
INLINE SUBQUERY:
NESTED SUBQUERY:
select * from employees where salary in (select salary from employees where
department_id=30);
CORRELATED SUBQUERY:
we could not able to execute inner query without help of outer query.