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
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int
1 1
2 1
3 2
4 2
tblOrganisationUsers
===========================
OrganisationUserID int | OrganisationID int | Firstname varchar | Lastname varchar
1 1 Bill Gates
2 1 Tom Crack
3 1 Paul Curran
4 1 Brian Walsh
5 1 John Doe
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 :
Role Name ReportsToID
CEO Bill Gates 1
CTO Tom Crack 1
General John Doe 2
Tech Brian Walsh 2
Tech John Doe 2
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
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int
1 1
2 1
3 2
4 2
tblOrganisationUsers
===========================
OrganisationUserID int | OrganisationID int | Firstname varchar | Lastname varchar
1 1 Bill Gates
2 1 Tom Crack
3 1 Paul Curran
4 1 Brian Walsh
5 1 John Doe
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 :
Role Name ReportsToID
CEO Bill Gates 1
CTO Tom Crack 1
General John Doe 2
Tech Brian Walsh 2
Tech John Doe 2
So the structure is based on Roles and then just sorted alphabetically by Rolename, Name
Any help/pointers appreciated