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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / 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

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

Answer / praveen

if we want to select 100th hig no.
in sub-query we will write 100 conditions.
to avoid this we go for correlated sub-query

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More DB2 Interview Questions

What is subquery ?

6 Answers  


If the base table underlying a view is restructured, eg. attributes are added, does the application code accessing the view need to be redone?

2 Answers  


How do I create a view in db2?

0 Answers  


What is an access path?

3 Answers  


What is a precompiler?

2 Answers  






How can you quickly find out the # of rows updated after an update statement?

0 Answers  


Explain the contents that are a part of dclgen.

0 Answers  


If a table has a column "dept" (declared to have nulls) and there are 10 rows in the table of which 3 have a null value in the dept column, what will select count(*) and select count(distinct dept) return?

6 Answers  


How to define the a field which accepts value till 99999.99 in db2

3 Answers  


what is the differences between spufi and qmf and which is better?

4 Answers   Accenture, Cap Gemini,


What is a lock?

1 Answers  


explain about index with examples

2 Answers   Syntel,


Categories