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-join

Author  Topic 

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-09-07 : 21:57:42
I have a table with columns similar to the following.

PERSON_PK, FIRST_NAME, LAST_NAME, SUPERVISOR_PK

The supervisor_pk value refers back to the person_pk value. I am looking for a query to return the PERSON with associated SUPERVISOR, I have done this in the past by creating a view, I could also use a table variable but I am wondering if anyone has any clever ways of doing this without either of those?



Future guru in the making.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-07 : 22:32:49
[code]SELECT p.PERSON_PK, p.FIRST_NAME, p.LAST_NAME, p.SUPERVISOR_PK, s.FIRST_NAME, s.LAST_NAME
FROM table1 p left JOIN table1 s
ON p.SUPERVISOR = s.PERSON_PK[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-09-07 : 23:29:33
Awesome, amazingly simple!



Future guru in the making.
Go to Top of Page
   

- Advertisement -