I have the below table
empid empname managerID
1 A NULL
2 B 1
3 C 1
4 D 2
Self join the table
case 1: all employees who have managers
select e1.empname employee, e2.empname manager
from employee e1
join employee e2 on e1.managerId = e2.empid
order by e2.name,e1.name
case 2: all employees who have managers or not
select e1.empname employee, COALESCE(e2.empname,'none') manager
from employee e1
left join employee e2 on e1.managerId = e2.empid
order by e2.name,e1.name