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

Using subquery


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

New User


Joined: 14 Dec 2005
Posts: 22
Location: India

PostPosted: Wed Jan 18, 2006 2:03 pm
Reply with quote

Hi all can we use subquery to retrive multiple rows.
My query is of like this
SELECT * FROM EMP
WHERE EMP_ID = (SELECT EMP_ID FROM TEMPA
WHERE DIR_ID =
( SELECT DIR_ID FROM TDIR
WHERE DIR_CTRY_CD <> 'US'));

For the above query I am getting an sql code of -811.
Can you guyz send me some sample subquery..
Back to top
View user's profile Send private message
radhakrishnan82

Active User


Joined: 31 Mar 2005
Posts: 435
Location: chennai, India

PostPosted: Wed Jan 18, 2006 2:06 pm
Reply with quote

Code:
can we use subquery to retrive multiple rows

Yes.
Use cursor to retrieve mulitple rows.

hope this helps.
Back to top
View user's profile Send private message
sairam

New User


Joined: 30 Aug 2005
Posts: 58
Location: Kolkata

PostPosted: Wed Jan 18, 2006 2:15 pm
Reply with quote

Hi,
try the following IN instead of '='

SELECT * FROM EMP
WHERE EMP_ID IN (SELECT EMP_ID FROM TEMPA
WHERE DIR_ID IN
( SELECT DIR_ID FROM TDIR
WHERE DIR_CTRY_CD <> 'US'));
Back to top
View user's profile Send private message
jwell rymbei

New User


Joined: 14 Dec 2005
Posts: 22
Location: India

PostPosted: Wed Jan 18, 2006 2:31 pm
Reply with quote

Hi,
Radhakrishnan.
i need to use the query in SPUFI only..

Sairam..
I tried with IN and it worked..thanks a lot...
you r the man..
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 Subquery inside a Updatable cursor in... DB2 8
No new posts Can we have correlated subquery in De... COBOL Programming 13
No new posts delete duplicate records using a subq... DB2 5
This topic is locked: you cannot edit posts or make replies. Difference between Corrrelated Subque... DB2 2
No new posts Upadate specific columns using Co-rel... DB2 8
Search our Forums:

Back to Top