Link to home
Create AccountLog in
Avatar of Dennis Matthews
Dennis Matthews

asked on

How to List direct and indirect reports of a colleague in access or excel

I have the below/attached employee table in an access database.  I need a query to find all the direct reports and indirect reports of a particular employee

EmpID      Fname      Lname      MngID
1      Fred      Flinstone      
2      Linda      Thompson      1
3      Sam      Adams      1
4      Jason      Williams      1
5      Michael       Jordan      2
6      Katey      Perry      5

If I wanted to find all the direct and indirect reports of EmpID 2,  it should return michael and Katey,   Excel or access should be ok

This is what I want to do but in access SQL Query to find all the subordinates of a superior
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

You can add this into column E and copy down

Open in new window

Please specify "direct and indirect reports of EmpID 2"
If you want to get hierarchical data via Access SQL then you need to study Celko's SQL Trees and Hierarchies in SQL for Smarties
For a quick reference here are 2 kind of explaining articles
on this subject : 1 , 2
Usually this kind of queries in Access are handled by a recursive function which populates a temporary table
Avatar of Dennis Matthews
Dennis Matthews


@Theo Kouwenhoven

In the example above, Michael is a direct report of Linda.  Katey is an indirect report of Linda.  Katey reports to Michael who reports to Linda.
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
@ Fabrice Lambert is there any quick way to convert to the nested set model for a large data set?
Do you mean migrate data from an existing table ?

Can you refine your need ?
A rather excellent example of solution "hijacking"...i must remember that people love solutions on a gold platter than time instead of providing link i just copy-paste...simple and point-guaranteed.
It will be great to award John points as well.