Could anyone clearly explain the diference between sub
query and correlated sub query?

Answer Posted / sriram

Correlated subquery runs once for each row selected by the
outer query. It contains a reference to a value from the
row selected by the outer query.

Nested subquery runs only once for the entire nesting
(outer) query. It does not contain any reference to the
outer query row.

For example

Correlated Subquery:

select e1.empname e1.basicsal e1.deptno from emp e1 where
e1.basicsal (select max(basicsal) from emp e2 where
e2.deptno e1.deptno)

Nested Subquery:

select empname basicsal deptno from emp where (deptno
basicsal) in (select deptno max(basicsal) from emp group by
deptno)



Please let me know if I am wrong...............

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can tablespace be moved to another dasd volume that is allocated for that tablespace?

756


What is null value in db2?

579


What is database reorganization?

599


How to test SQL -911 error while developing COB-DB2 program

6732


How to find the number of rows in a db2 table?

654






How does cobol compile db2 program?

619


Why db2 is called db2?

602


Name the various locking levels available?

642


What is db2?

751


How do you pull up a query which was previously saved in qmf?

684


What is the result of open cursor statement?

644


What is with ur in db2?

772


What are the various isolation levels possible?

661


List out the data types available.

712


Explain correlated sub-queries.

594