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

Is the below one Correlated Sub-Query


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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Feb 27, 2009 7:16 pm
Reply with quote

Hi,

I am executing below given queries using SPUFI and getting the same number !

JOIN Query:

Code:

SELECT COUNT(A.ORDER_KEY) FROM DB01.ORDER_TAB A,
                               DB01.ORDER_PERS B
 WHERE A.ORDER_CD = '13'                       
   AND A.ORDER_YR = '2007'                     
   AND A.ORDER_IND = 'Y'                       
   AND A.ORDER_KEY = B.ORDER_KEY               
WITH UR;                                       


Is the below one a Sub-Query?

Code:

SELECT COUNT((A.ORDER_KEY) FROM DB01.ORDER_TAB A
 WHERE A.ORDER_CD = '13'                         
   AND A.ORDER_YR = '2007'                       
   AND A.ORDER_IND = 'Y'                         
   AND A.ORDER_KEY IN                           
       (SELECT B.ORDER_KEY FROM DB01.ORDER_PERS B
         WHERE A.ORDER_KEY = B.ORDER_KEY)       
WITH UR;                                         


Is the below one Correlated Sub-Query?

Code:

SELECT COUNT(A.ORDER_KEY) FROM DB01.ORDER_TAB A     
 WHERE A.ORDER_CD = '13'                           
   AND A.ORDER_YR = '2007'                         
   AND A.ORDER_IND = 'Y'                           
   AND EXISTS                                       
       (SELECT B.ORDER_KEY FROM DB01.ORDER_PERS B
         WHERE A.ORDER_KEY = B.ORDER_KEY)           
WITH UR;                                           


All of them are giving me the correct COUNT only. I would like to know which variety each one belongs to..... Please help.

Thanks.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Feb 27, 2009 7:17 pm
Reply with quote

Please ignore two braces after COUNT in the 2nd query icon_redface.gif
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Feb 27, 2009 9:22 pm
Reply with quote

2nd and 3rd are co-related subqueries one with IN clause and other with EXISTS ...
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Feb 27, 2009 9:38 pm
Reply with quote

ashimer, Thanks for the info. How a sub-query would look like for the same scenario?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Feb 27, 2009 9:42 pm
Reply with quote

Code:


SELECT COUNT(A.ORDER_KEY) FROM DB01.ORDER_TAB A
 WHERE A.ORDER_CD = '13'                         
   AND A.ORDER_YR = '2007'                       
   AND A.ORDER_IND = 'Y'                         
   AND A.ORDER_KEY IN                           
       (SELECT ORDER_KEY FROM DB01.ORDER_PERS )

Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Mon Mar 02, 2009 4:04 pm
Reply with quote

Thanks. icon_biggrin.gif
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top