Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

It is very similar to sub-queries where the parent query is executed based on the values

returned by sub-quries. but when come’s to co-related subqueries for every instance of parent
query subquery is executed and based on the result of sub-query the parent query will display
the record as we will have refernce of parent quries in su-queries we call these as corelated
subquries.
so, we can define co-related sub query as for every record retrival from the sub query is
processed and based on result of process the parent record is displayed.

The main differencre between subquery and co-related subquery is that in subquery child
query is executed first n then parent but in co-related subquery main query is executed
first(even though parenthesis are present) and then child query.

Example of co-related subquery for the emp and dept tables under Scott

-- The following query display the dept. name in which there are employess

select dname from dept where not exists


(select deptno from emp
where dept.deptno = emp.deptno);

-- The following query display the dept. name in which there is no employee.

select dname from dept where not exists


(select deptno from emp
where dept.deptno = emp.deptno);

You might also like