List All Employee'S Names and Their Managers by Manager Name Using an Inner Join

SQL how to connect Managers to employee

You need to use inner join for entire solution and case .. when expression specially for the manager row as follows:

SELECT emp.NAME employee_name, 
Case when <> then mgr.NAME end as manager_name
FROM emp JOIN department d ON = emp.dept_id
JOIN emp mgr ON d.mgr_id =

SQL: Employee, Manager, City Names

JOIN returns all rows from tables where the key record of one table is equal to the key records of another table

INNER JOIN returns only matching tuples/rows if there is a much on the right of he compared tables.

While LEFT OUTER JOIN returns all matching tuples/rows from both compared tables.

I recommend that you use LEFT OUTER JOIN in your case.

Related Topics

Leave a reply