Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DB2 SQL Query Needed?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: DB2 SQL Query Needed?
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

Site Director


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

PostPosted: Tue Jun 19, 2007 1:35 pm    Post subject:
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    Post subject: Hi
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    Post subject:
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    Post subject: Hi
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    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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
This topic is locked: you cannot edit posts or make replies. SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us