Sub query
What is diffrence between Co-related sub query and nested sub query?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arjun PanwarPosted Nov 23, 2011, 5:10 AM
TulasiPosted Nov 23, 2011, 5:00 AM
Ex: select * from emp where (deptno,basicsal) in (select deptno,max(basicsal) from emp group by deptno)
where as
Co-related Sub Query : is executed for every row of Outer or main Query , outer query is executed first and result is sent to inner query for execution
Ex: select * from emp e1 where e1.basicsal=(selcte max(basicsal) from emp e2 where e2.deptno=e1.deptno)
Arjun PanwarPosted Nov 23, 2011, 4:11 AM
Arjun PanwarPosted Nov 23, 2011, 3:57 AM
AartiPosted Nov 23, 2011, 3:46 AM
A correlated Subquery runs for the rows selected from the outer query.
It takes the value from the outer query
and execute the inner query for that value
example:
select * from Employee e
where e.deptno in(select d.deptno from dept d
where e.deptno = d.deptno);
in this query Employee table's deptno will be passed into the inner query(select deptno from dept d where e.deptno = d.deptno.
And the inner query will execute only for that value from the outer query.
That's why it is called correlated subquery
In Nested subquery the inner query runs only once and pass the result set to the outer query.
example:
select * from Employee e
where e.deptno in (select d.deptno from dept d);
Here the inner query (select d.deptno form dept d) will run first and fetches all the rows from the dept table
and the outer query will select only the records that has the matching deptno in the result set fetched by the
inner query. The outer query will act as a nesting query and that is why this is called nested subquery.
Here in correlated subquery, the outer query executes first and the inner query will execute second.
But in Nested subquery, the inner query executes first and the outer query executes second.
Hope this helps.
Thanks
Satyapriya NayakPosted Nov 23, 2011, 3:44 AM
A correlated Subquery runs for the rows selected from the outer query. It takes the value from the outer query
and execute the inner query for that value
example:
select * from emp e
where e.deptno in(select d.deptno from dept d
where e.deptno = d.deptno);
in this query emp table's deptno will be passed into the inner query(select deptno from dept d where e.deptno = d.deptno#.
And the inner query will execute only for that value from the outer query.
That's why it is called correlated subquery
In Nested subquery the inner query runs only once and pass the result set to the outer query.
example
select * from emp e
where e.deptno in#select d.deptno from dept d#;
Here the inner query #select d.deptno form dept d) will run first and fetches all the rows from the dept table
and the outer query will select only the records that has the matching deptno in the result set fetched by the
inner query. The outer query will act as a nesting query and that is why this is called nested subquery.
Here in correlated subquery, the outer query executes first and the inner query will execute second.
But in Nested subquery, the inner query executes first and the outer query executes second.
Refer the link
http://en.allexperts.com/q/Oracle-1451/2009/7/Diff-Nested-Correlated-subqueries.htm
Thanks