Wednesday 13 March 2013

What is difference between sub query & correlated sub query?

Subquery is a select statement that is nested within another select statement which returned intermediate result. i.e.
select ename from emp
where empno in (select empno from incr)

Correlated subquery is a nested subquery which is executed once for each ‘candidate row’ by the main query & which on execution use a value from a column in the outer query. i.e.
select empno,ename from emp
where 1 <
(select count(*) from incr where empno =emp.empno);

No comments:

Post a Comment