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 ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is db2 a programming language?

616


How does coalesce work?

594


How to fetch the last row from the table in SQL (db2)?

1045


How do I change the column size in db2?

611


How to execute stored procedures?

630






What are the various isolation levels possible?

661


How and when does the db2 enforces the unique key?

625


Which component is responsible for db2 startup and shutdown?

639


Are views updateable?

651


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

6732


When a COBOL-DB2 program in PRODUCTION is updating main tables and gone for long run, what have to do?

3130


Which isolation level provides highest data integrity?

607


Comment whether dclgen is mandatorily used. If not, then what is the point of using it?

621


How to find primary key of a table in db2?

626


What is a bind card?

691