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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 self joining a single table to get matched data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-03 : 08:24:36
ibadathulla writes "I got a single table where in it contains three fields the table Employee look like this

id Empname managerid
--------------------------------------
1 aaa 2
2 bbb 3
3 ccc 4
4 ddd 1
--------------------------------------
the resultant output should be like this when i write a single query for the above table using inner join(self join)

Empname managername
--------------------------------------
aaa bbb
bbb ccc
ccc ddd
ddd aaa"

mr_mist
Grunnio

1870 Posts

Posted - 2004-09-03 : 08:30:39
Try something like

SELECT a.empname, b.managername from yourtable a inner join yourtable b on a.managerid = b.id

-------
Moo. :)
Go to Top of Page
   

- Advertisement -