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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

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