I have a table called Staff which has the following fields: idStaff, Name, Phone, Email, SupervisorId.
The SuervisorId is the idStaff of that staff member's supervisor.
I want to show the list of all staff members with their basic info (Name, Email etc) as well as the name of their supervisor.
So something like this:
select idStaff
, Name
, Email
, Phone
, (select Name from Staff where idStaff = SupervisorId) as SupervisorName
from Staff
order
by Name ASC
The query does not work. I tried joining the two tables but I am confused on how to get the Name from the subquery in the join.
select idStaff
, Name
, Phone
, Email
from Staff a
inner
join Staff b
on a.idStaff = b.SupervisorId
order
by Name ASC