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

DB2 SQL Query Needed?


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

New User


Joined: 11 May 2007
Posts: 10
Location: Mumbai

PostPosted: Tue Jun 19, 2007 11:15 am
Reply with quote

I have a table 'TB1' with the below columns,

Emp-No,EmpName,Dept,manager...etc.

Now I want to retrive the data from dept wise and i want find those employees who are working under a specific Mangager?

Dept1------->Manager1----->Emp1
Emp2
Emp3
Dept2------->Manager2----->Emp4
Emp5
Emp6
Dept3------->Manager3----->Emp7
Emp8
Emp9

Please tell me the query for the above requirement in TB1?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jun 19, 2007 1:35 pm
Reply with quote

Hello,

Please post a more representative sample of your data and what you want the result to be. What you have psoted is not clear.

Show the data in the table as one part of your information and what you want for the result of the query as aonther.
Back to top
View user's profile Send private message
bajibabu

New User


Joined: 01 Aug 2005
Posts: 5
Location: hyderabad

PostPosted: Tue Jun 19, 2007 1:56 pm
Reply with quote

The following query may suit for ur need.

SELECT *
FROM EMP
ORDER BY DEPT,MANAGER;
Back to top
View user's profile Send private message
haidude

New User


Joined: 11 May 2007
Posts: 10
Location: Mumbai

PostPosted: Tue Jun 19, 2007 2:02 pm
Reply with quote

I want below details from the table,
1) Details of each Department.
2) Manager's details from each Department.
3) The employees details from each department Under a manager.
Back to top
View user's profile Send private message
bajibabu

New User


Joined: 01 Aug 2005
Posts: 5
Location: hyderabad

PostPosted: Tue Jun 19, 2007 2:32 pm
Reply with quote

Consider the following sample table

Emp-No,EmpName,Dept,manager

EMP-NO EMP-NAME DEPT MANAGER
1000 AAAAA D1 MGR1
1001 BBBBB D1 MGR2
1002 CCCCC D1 MGR1
1003 DDDDD D2 MGR3
1004 YYYYYY D3 MGR4
1005 XXXXX D1 MGR6
1006 RRRRR D3 MGR5

BY THE FOLLOWING QUERY
SELECT DEPT,MANAGER,EMP-NO
FROM EMP
ORDER BY DEPT,MANAGER,ENP-NO;

YOU WILL GET THE FOLLOWING O/P:


DEPT MANAGER EMP-NO
D1 MGR1 1000
D1 MGR1 1002
D1 MGR2 1001
D1 MGR6 1005
D2 MGR3 1003
D3 MGR4 1004
D3 MGR5 1006

FROM ABOVE O/P U CAN GET EASILY THE INFO U WANT.IF U WANT EMP NAME ALSO U CAN USE THAT IN SELECT CLAUSE.
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
Search our Forums:

Back to Top