Professional Documents
Culture Documents
SUBQUERY
SUBQUERY
SUBQUERY
==========
Outer query(inner query/subquery)
in non correlated subquery you csn write two seperate queries and merge it using
logic
Qn: Find the name of the employee who is earning max salary
2.Multiple row subquery:-IN,ALL,ANY(if you try to run inner query you will get
multiple rows
=======================
Fetch the name and salary of the employees who is getting more salary than the
employees working in department 60?
find the comparison between the employee who is working in department 10 along with
the highest and lowest salaries in the whole group?
SELECT FIRST_NAME,
(SELECT MAX(SALARY)FROM EMPLOYEES),
SALARY,
(SELECT MIN(SALARY)FROM EMPLOYEES),
DEPARTMENT_ID
FROM EMPLOYEES WHERE DEPARTMENT_ID=10;
5.NESTED SUBQUERY:-WHERE CLAUSE -- Single row, multiple rows colums are example of
nested subquery
=================
6.CORRELATED SUBQUERY:-
=====================
Find the details of the employeeS who is working NOT IN atleast one of the
projects?
EMPL1
PRJCT
select * from empl1 where eid in(select eid from prjct where empl1.eid=prjct.eid);
find the names of the employees who are getting maximum salary department wise?
select first_name,salary,department_id from employees
where (salary,department_id)in (select max(salary),department_id from employees
group by department_id);