Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Join in SQL Query vickey_dw DB2 1 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us