Retrieving a linked list relation from a starting node

Viewed 21

Imagine we have an Employee - Supervision relation like the image below:

Employee Supervision

Where we can basically retrieve all "Manager - Employee" relations with:

 SELECT E.lastName AS "Employee", M.lastName AS "Manager"
    FROM Employees E LEFT OUTER JOIN 
      (Supervisions S INNER JOIN Employees M 
        ON S.managerID = M.employeeID)
      ON E.employeeID = S.employeeID
    ORDER BY E.lastName

How could we retrieve a walk from any specific employee to all employees it supervises?

Similarly this relation can be abstracted and applied to anyone saving a graph using 2 tables in any SQL database and trying to walk it.

This question is based on studies from Tom Jewett (where I borrowed images & examples) https://web.csulb.edu/colleges/coe/cecs/dbdesign/dbdesign.php?page=recursive.php

0 Answers
Related