DB schema

For this table, I am writing a query (in the oraklovsky, native syntax)

SELECT EMPLOYEES.last_name as employee_name, EMPLOYEES.manager_id as employee_manager, DEPARTMENTS.manager_id as department_manager FROM EMPLOYEES, DEPARTMENTS WHERE ( EMPLOYEES.department_id = DEPARTMENTS.department_id AND EMPLOYEES.manager_id <> DEPARTMENTS.manager_id ); 

How to substitute in the columns employee_manager and department_manager instead of id the last_name value corresponding to these id ?

    1 answer 1

    Incomprehensible question. Which means

    "How to substitute in the columns employee_name and department_name instead of id the last_name value corresponding to these id?"

    You have already written EMPLOYEES.last_name as employee_name , i.e. last_name substituted into the employee_name column.

    UPDATE

    Just add two more times the table of employees:

     SELECT EMPLOYEES.last_name as employee_name, emp_man.last_name AS employee_manager, dept_man.last_name as department_manager FROM EMPLOYEES, DEPARTMENTS, employees emp_man, employees dept_man WHERE (EMPLOYEES.department_id = DEPARTMENTS.department_id AND EMPLOYEES.manager_id != DEPARTMENTS.manager_id AND employees.manager_id = emp_man.EMPLOYEE_ID (+) AND DEPARTMENTS.manager_id = dept_man.EMPLOYEE_ID (+)) 
    • Fixed a typo in the question, thanks - will_hunting