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

SQL Qstn


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

New User


Joined: 03 Apr 2008
Posts: 82
Location: United States

PostPosted: Mon Dec 07, 2009 2:52 pm
Reply with quote

I have a DB2 table:

Columns:

Emp ID
Emp Name
Emp Age
Emp Manager
Manager's ID

I ned all Emp ID and Name whose Age is greater than their respective managers age.

Pls suggest the best solution.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Dec 07, 2009 3:13 pm
Reply with quote

What have you tried so far?

Do a self join of the table on emp_id and manager_id with the age condition or else use a correlated subquery for the age .
Back to top
View user's profile Send private message
CICS fan

New User


Joined: 03 Apr 2008
Posts: 82
Location: United States

PostPosted: Mon Dec 07, 2009 3:16 pm
Reply with quote

I am in sea with this. Could u be a bit specific kindly.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Dec 07, 2009 3:20 pm
Reply with quote

Quote:

I am in sea with this


??

Code:

SELECT EMP_ID FROM TABLE A
WHERE EMP_AGE > (SELECT MANAGER_AGE FROM TABLE B
WHERE EMP_ID = A.EMP_ID)
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Dec 07, 2009 4:28 pm
Reply with quote

Hello There,

I think below query will give desired results

Code:
Select EMP_ID from Table A
Where Emp_Age >( Select Emp_Age From Table B
                             Where A.Manager's_ID =B.Emp_id)
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

 


Search our Forums:

Back to Top