Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
What is Correlated subquery

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
ensameer

New User


Joined: 15 Mar 2005
Posts: 4
Location: Chennai

PostPosted: Wed Mar 16, 2005 2:26 pm    Post subject: What is Correlated subquery
Reply with quote

What is Correlated Subquery ?
-Sameer
Back to top
View user's profile Send private message
References
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Wed Mar 16, 2005 2:42 pm    Post subject:
Reply with quote

hi sameer,

in correlated subquery the outer query is executed first and depending on the result of it for each and every record the inner query is executed.


Cheers............

pavan
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 200
Location: Keane India Ltd., Hyderabad

PostPosted: Wed Mar 16, 2005 6:28 pm    Post subject: Re: correlated subquery
Reply with quote

Hi,

Correlated sub query is a type of sub query in which Outer Query is executed at once (fetches one row) and by taking that values inner query will be executed for all rows. Then outer query fetches 2nd row then inner query will be executed for all rows and so on.

To clearly under stand see the following example which finds nth max sal

SELECT SAL FROM EMP A WHERE N = (SELECT COUNT(*) FROM EMP B WHERE A.SAL<=B.SAL);

Outer Query fetches 1 row and inner query compares it with all salaries. Then outer query fetches 2nd row and so on.

Thanks,
Reddy.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1