Im having the following table , each employee have a manager, if a guy is his own manager den the managerid field is null, i want emid name and manager id as result
emid name and manager id
SELECT e1.emid, e1.name, COALESCE(e2.name, e1.name) AS managername FROM employee e1 LEFT JOIN employee e2 ON e1.managerid = e2.emid