Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query using self join

Author  Topic 

senthilaa
Starting Member

12 Posts

Posted - 2008-01-23 : 04:16:14
Table EMP
EMP_ID EMP_NAME
1 A
2 B

Table MgrID
EMP_ID Mgr_ID
1 2

How to have the following result
EmpName Mgr_Name
A B


-Senthil

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-23 : 04:26:18
SELECT t1.EMP_NAME AS EmpName ,t2.EMP_NAME AS Mgr_Name
FROM EMP t1
INNER JOIN MgrID m
ON m.EMP_ID=t1.EMP_ID
INNER JOIN EMP t2
ON t2.EMP_ID=m.Mgr_ID
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-23 : 07:12:38
For more levels read about Expanding Hierarchies in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -