Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends
I have table like that

SQL
EmpID	EmpName	ManagerId
1	Viraj	6
2	Yatin	1
3	Ravi	6
4	Nikunj	3
5	Bhavesh	3
6	Viral	6
7	Mukesh	8
8	Nilesh	6



now i wabt select EmpName and ManagerId as Manager which ManagerId like EmpID menas

SQL
EmpName ManagerName
Viraj   Viral
Yatin   Viraj
Ravi    Viral
Nikunj  Ravi


how can i do that....
Thank You all...
Posted

1 solution

Self-join
SQL
select e1.empid,e1.empnm,e2.empnm as ManagerNm 
from emptbl e1
left join emptbl e2 on e1.ManagerId = e2.EmpId 

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900