I have three tables, I am looking to get a dendritic structure of organisation roles and who they report to.
A sample might be
tblOrganisationRoles
===========================
OrganisationRoleID int | OrganisationID int | Role varchar
1 1000 CEO
2 1000 CTO
3 1000 Tech
4 1000 General
5 1000 CFO
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int
1 1
2 1
3 2
4 2
5 1
tblOrganisationUsers
===========================
OrganisationUserID int | OrganisationID int | OrganisationRoleID | Firstname varchar | Lastname varchar
1 1000 1 Bill Gates
2 1000 2 Tom Crack
3 1000 3 Paul Curran
4 1000 3 Brian Walsh
5 1000 4 John Doe
6 1000 5 Paul Hand
This structure would know to have CEO as the root because of the record in tblOrganisationRoleOrgChart
as CEO reports to himself This will always be the way, after this it is a case of finding out who reports
to CEO and building it up. If 2 roles report to one role as is the case with Tech and General who
report to CTO then then we sort alphabetically, so General appears first then Tech. If I were to sort
the data above I would be trying to get :
CEO
Bill Gates
CFO
Paul Hand
General
John Doe
Tech
Brian Walsh
Paul Curran
CTO
Tom Crack
So the structure is based on Roles and then just sorted alphabetically by Rolename, Name
Any help/pointers appreciated
A sample might be
tblOrganisationRoles
===========================
OrganisationRoleID int | OrganisationID int | Role varchar
1 1000 CEO
2 1000 CTO
3 1000 Tech
4 1000 General
5 1000 CFO
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int
1 1
2 1
3 2
4 2
5 1
tblOrganisationUsers
===========================
OrganisationUserID int | OrganisationID int | OrganisationRoleID | Firstname varchar | Lastname varchar
1 1000 1 Bill Gates
2 1000 2 Tom Crack
3 1000 3 Paul Curran
4 1000 3 Brian Walsh
5 1000 4 John Doe
6 1000 5 Paul Hand
This structure would know to have CEO as the root because of the record in tblOrganisationRoleOrgChart
as CEO reports to himself This will always be the way, after this it is a case of finding out who reports
to CEO and building it up. If 2 roles report to one role as is the case with Tech and General who
report to CTO then then we sort alphabetically, so General appears first then Tech. If I were to sort
the data above I would be trying to get :
CEO
Bill Gates
CFO
Paul Hand
General
John Doe
Tech
Brian Walsh
Paul Curran
CTO
Tom Crack
So the structure is based on Roles and then just sorted alphabetically by Rolename, Name
Any help/pointers appreciated