I am trying to write an SQL query in Access that will return the relative position of an item/person in a linear network.
For example if we have a table which contains data regarding employees including their first line manager.
| Employee | Employee ID | Manager | Manager ID |
--------------------------------------------------
| John | 123 | Craig | 321 |
| Craig | 321 | Claire | 874 |
| Claire | 874 | Ben | 366 |
I could find an employees 2nd, 3rd... line managers by doing something like this
SELECT t1.Employee, t1.Manager, T2.[Manager] AS [2ndManager], t3.[Manager] As [3rdManager]
FROM ((StaffTable t1
LEFT JOIN StaffTable t2 ON t1.[Manager ID] = t2.[Employee ID])
LEFT JOIN StaffTable t3 ON t2.[Manager ID] = t2.[Employee ID])
In the example above t1.Employee could refer to someone who is already a 2nd or 3rd line manager. I am unsure how to get an individuals rank e.g. the number of levels there are below them (node height)
Could anyone advise on how best to go about this?