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 2008 Forums
 Transact-SQL (2008)
 How to use self join

Author  Topic 

shinelawrence
Starting Member

32 Posts

Posted - 2013-10-04 : 07:25:51
Hi Everyone,
how to use self join like this scenario.

Table:
Empid Empname ManagerID
1 Arul Null
2 Satya 1
3 feddy 1
4 Lawce 2

I need to get the o/p:

Empid Empname Manager
1 Arul Null
2 Satya Arul
3 feddy Arul
4 Lawce Satya.... How to get...Pls tell the solution.

Thanks & Advanced

Lawce

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-04 : 07:41:32
just include table once more in join

SELECT t1.Empid, t1.Empname, t2.Empname AS Manager
FROM Table t1
LEFT OUTER JOIN Table t2
On t2.Empid = t1.managerID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

shinelawrence
Starting Member

32 Posts

Posted - 2013-10-04 : 08:02:10
thank u very much....

Lawce
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-04 : 08:51:02
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -