View previous topic :: View next topic
|
Author |
Message |
haidude
New User
Joined: 11 May 2007 Posts: 10 Location: Mumbai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
bajibabu
New User
Joined: 01 Aug 2005 Posts: 5 Location: hyderabad
|
|
|
|
The following query may suit for ur need.
SELECT *
FROM EMP
ORDER BY DEPT,MANAGER; |
|
Back to top |
|
|
haidude
New User
Joined: 11 May 2007 Posts: 10 Location: Mumbai
|
|
|
|
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 |
|
|
bajibabu
New User
Joined: 01 Aug 2005 Posts: 5 Location: hyderabad
|
|
|
|
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 |
|
|
|