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
SELECT emid, name,
CASE WHEN s.managerid IS NULL THEN s.name ELSE m.name END managername
FROM employees s
LEFT JOIN employees m ON s.managerid = m.managerid
OR
SELECT emid, name, m.name managername
FROM employees s
LEFT JOIN employees m ON COALESCE(s.managerid, s.emid) = m.emid