I have two tables Employee and Department this image shows the manager of every employee. I want to write a SQL query that gives me a list of all the supervisor (Mana
This is the solution to my question
with recursive p as (
WITH emp_dept as(
SELECT employee_id,manager_id
FROM employee,department
WHERE employee.dept_id= department.dept_id
)
select e1.employee_id, e1.manager_id
from emp_dept e1
where e1.employee_id = 202
union
select e2.employee_id , e2.manager_id
from p
join emp_dept e2 ON e2.employee_id = p.manager_id
)
select manager_id
from p
I think you can use "hierarchical queries" for Oracle and try this:
select manager_id supervisor
from employee
start with employee_id = 202
connect by nocycle employee_id = prior manager_id;