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

Shall i use this query to retrieve first 4 records, Select empno, sal from emptbl where empno < 5. like this can we fetch first 100 records?

3 Answers  


What is a DB2 bind?

3 Answers  


select 100 records from million records ?

2 Answers   Verizon,


i want to maintain uniqueness on pdf without make lf??????????

0 Answers  


What is null indicator in db2?

0 Answers  






What is coalesce in db2?

0 Answers  


what is datacom db?

2 Answers   CSC,


Explain about cursor stability?

0 Answers  


How can you display the current date & current time ?

1 Answers   Cap Gemini,


How can the duplicate values be eliminated from db2 select?

0 Answers  


How will you delete duplicate records from a table?

7 Answers   Google,


For a db2 column that is being defined as decimal (11, 2), discuss the cobol picture clause.

0 Answers  


Categories