Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive ctes


Great job! Let's get back to our original query that shows the path from the boss to every employeesyee. We can modify this to show a few more ways to retrieve other information.


Let's assume that 'distance' in our hierarchical company is the number of people from the boss to that person. According to this definition, the boss will have a distance of 0, their direct subordinates: 1, the subordinates of those people: 2, etc.

Now, add another column (named Distance) to the template query. It shows the distance from each employee to the boss.

Stuck? Here's a hint!

Simply add a new column in the CTE that will be equal to 0 for the boss, and add one in each step.