IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

What is Correlated subquery


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ensameer

New User


Joined: 15 Mar 2005
Posts: 4
Location: Chennai

PostPosted: Wed Mar 16, 2005 2:26 pm
Reply with quote

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

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Wed Mar 16, 2005 2:42 pm
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: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Wed Mar 16, 2005 6:28 pm
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Subquery inside a Updatable cursor in... DB2 8
No new posts Can we have correlated subquery in De... COBOL Programming 13
No new posts delete duplicate records using a subq... DB2 5
This topic is locked: you cannot edit posts or make replies. Difference between Corrrelated Subque... DB2 2
No new posts Upadate specific columns using Co-rel... DB2 8
Search our Forums:

Back to Top