Let us first create the same table for an employee.
One
of the columns in the same table contains the ID of the manger, who is
also an employee for the same company. Now all the employees and their
managers are present in the same table.
Let us now connect the Employee table with itself with the help of INNER JOIN.
-- Inner Join--
SELECT e1.Employee EmployeeName, e2.Employee AS ManagerName FROM employee e1 INNER JOIN employee e2 ON e1.Manage_id = e2.ID -- Self Join -- SELECT A.Employee as EmployeeName , B.Employee as ManagerName From employee A , employee B WHERE A.Manage_id=B.ID Result Like That: |