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
DatabasesMicrosoft AccessMicrosoft ExcelVB ScriptVBA

Avatar of undefined
Last Comment
Fabrice Lambert

8/22/2022 - Mon
Shaun Vermaak

You can add this into column E and copy down

Open in new window

Theo Kouwenhoven

Please specify "direct and indirect reports of EmpID 2"
John Tsioumpris

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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
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.
Fabrice Lambert

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dennis Matthews

@ Fabrice Lambert is there any quick way to convert to the nested set model for a large data set?
Fabrice Lambert

Do you mean migrate data from an existing table ?

Can you refine your need ?
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
John Tsioumpris

A rather excellent example of solution "hijacking"...i must remember that people love solutions on a gold platter than directions...next time instead of providing link i just copy-paste...simple and point-guaranteed.
Fabrice Lambert

It will be great to award John points as well.