• I tend to roll-my-own when it comes to Hierarchies.

    Here's how I do it.

    Say I have a list of Employees with a Key on ID

    I then make a Employee_Hierarchy table then an Employee_SuperHierarchy table

    Employee_Hierarchy contains the parent and child Employee Primary Keys and is a compound unique index.

    Employee_SuperHierarchy contains the parent and child Employee Primary key and the Gap.

    For every Employee row there's an Row in with Gap=0

    It contains the expanded hierarchy so if (A) is the boss of (B) and (B) is the boss of (C) then

    A, A, 0

    B, B, 0

    C, C, 0

    A, B, 1

    B, C, 1

    A, C, 2

    You can then loop until no more are inserted to build the full hierarchy by

    INSERT INTO Employee_SuperHierarchy

    (Parent, Child, Gap)

    SELECT Parent.ParentID

    , Child.ChildID

    , Child.Gap + 1

    FROM Employee_SuperHierarchy Child

    INNER JOIN Employee_Hierarchy Parent

    ON Child.ParentID = Parent.ChildID

    Then you can easily run a query to find all the employees (or Bosses) of a person. Do make sure to exclude Gap = 0 (employs self/Self boss)

    E.g. To find all the employees

    SELECT Employee.*

    FROM Employee Boss

    INNER JOIN Employee_SuperHierarchy

    ON Employee_SuperHierarchy.ParentID = Boss.ID

    INNER JOIN Employee

    ON Employee.ID = Employee_SuperHierarchy.ChildID

    WHERE Boss.Name = 'Stalin'