Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Is the below one Correlated Sub-Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Is the below one Correlated Sub-Query
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Is the below one Correlated Sub-Query
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    Post subject:
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    Post subject: Reply to: Is the below one Correlated Sub-Query
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us