What you need in this case is to make a SELF JOIN
, that is, make the union of tables with the same table of EMPLOYEES
to be able to find the information of the manager.
The first point to correct is to stop using implicit% JOIN
and start using explicit JOIN
, since the functionality of using JOIN
implicit is considered deprecated since 1992.
The query would be as follows:
SELECT
E.FIRST_NAME || ' ' || E.LAST_NAME AS "NOMBRE COMPLETO DEL EMPLEADO"
,D.DEPARTMENT_ID
,D.DEPARTMENT_NAME
,D.MANAGER_ID
,EE.FIRST_NAME || ' ' || EE.LAST_NAME AS "NOMBRE COMPLETO DEL MANAGER"
FROM EMPLOYEES E
INNER JOIN DEPARTMENTS D
ON E.DEPARMENT_ID = D.DEPARMENT_ID
INNER JOIN EMPLOYEES EE
ON E.MANAGER_ID = E.EMPLOYEE_ID
Magic occurs in JOIN
:
INNER JOIN EMPLOYEES EE
ON E.MANAGER_ID = E.EMPLOYEE_ID
If you can notice, by matching the field MANAGER_ID
with EMPLOYEE_ID
you are saying that you are going or get the manager's data through your employee id, since the manager is likewise another employee.
Note: For more information about the differences between JOIN
implicit% and JOIN
explicit, this great response can clear up the picture.