Reputation: 3806
I have a table with columns EMPLOYEEID
, EMPLOYEENAME
, MANAGERID
.
MANGERID
is from the column EMPLOYEEID
. SOME EMPLOYEEID
don't have any manangerid
(i.e. NULL). Now I need a output from query such that it returns EMPLOYEENAME
and corresponding MANGERNAME
.
How can It be done?
I have tried self joins but not able to get desired output.
Upvotes: 2
Views: 871
Reputation: 79929
You will need a self join, with LEFT JOIN
to get those that has no manager:
SELECT
e.EMPLOYEEID,
e.EMPLOYEENAME,
m.EmployeeName AS ManagerName
FROM Employees AS e
LEFT JOIN Employees AS m ON e.ManagerId = m.EmployeeID;
Upvotes: 2