MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is (select col from a) allowed in select of query

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
timfoster
Beginner


Joined: 08 Jul 2004
Posts: 12
Topics: 5

PostPosted: Thu Oct 19, 2006 12:47 pm    Post subject: Is (select col from a) allowed in select of query Reply with quote

Folks,

can anyone tell me if the following works in db2. I am trying to use the
second select to get a column from a table that I don't want to add to my
main query although I suppose I can use a left outer join.

Code:

SELECT                                                     
PER.SOCSECNO,                                             
(SELECT GTNAMT FROM F8IO.ISI_PYH_GTN_T   //wondering                   
     WHERE EMPLID = BAS.EMPLID                    //about this select         
     AND   ORGID = BAS.ORGID                               
     AND   GTNNO = 162) TIMS                               
FROM                                                       
F8IO.ISI_EDB_PER_T PER                                     
INNER JOIN                                                 
F8IO.ISI_EDB_BAS_T BAS                                     
ON PER.QTRNO = BAS.QTRNO                                   
AND PER.EMPLID = BAS.EMPLID                               
AND PER.ORGID = BAS.ORGID                                 
WHERE PER.QTRNO = 0                                       
AND BAS.EMPLSTAT IN ('A','L','P');



thanks muchly
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Thu Oct 19, 2006 12:57 pm    Post subject: Reply with quote

timfoster,

The SELECT statement is used to create a Temp table named TIMS from which are selecting certain values.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
timfoster
Beginner


Joined: 08 Jul 2004
Posts: 12
Topics: 5

PostPosted: Thu Oct 19, 2006 1:55 pm    Post subject: Reply with quote

So with DB2 then you are not allowed to use the second select the way I am trying? As you mention, it needs to be added to the from clause to create a temporary table which I can join to. Something more like

Code:


SELECT                                                 
PER.SOCSECNO,                                         
CHAR(GTN.GTNAMT)                                       
FROM                                                   
F8IO.ISI_EDB_PER_T PER                                 
INNER JOIN                                             
F8IO.ISI_EDB_BAS_T BAS                                 
ON PER.QTRNO = BAS.QTRNO                               
AND PER.EMPLID = BAS.EMPLID                           
AND PER.ORGID = BAS.ORGID                             
LEFT OUTER JOIN                                       
(SELECT ORGID, EMPLID, GTNAMT FROM F8IO.ISI_PYH_GTN_T 
     WHERE GTNNO = 162 ) GTN                           
ON  BAS.EMPLID = GTN.EMPLID                           
AND BAS.ORGID = GTN.ORGID                             
WHERE PER.QTRNO = 0                                   
AND BAS.EMPLSTAT IN ('A','L','P');


thanks

Tim
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Thu Oct 19, 2006 2:24 pm    Post subject: Reply with quote

timfoster,

Yes it needs to something like that. Read this topic which explains about using the select query(Check the solutions posted by me)

http://www.mvsforums.com/helpboards/viewtopic.php?t=4188&highlight=explain


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
timfoster
Beginner


Joined: 08 Jul 2004
Posts: 12
Topics: 5

PostPosted: Thu Oct 19, 2006 3:17 pm    Post subject: Reply with quote

thanks for the help
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group