I have 2 tables:
1. Team
id group_head initial_team
id : for id table (auto increment)
Group Head : employee id to add group head
initial team : initial team for this team
2. Team Sub
id team_id employee_id parent parent_id
id : id for table (auto increment)
team_id : id of the Team_table
employee_id : employee id
parent : value 0 if they child from team_sub, value 1 if they child from team
parent_id : if parent value 1 the parent id is id team, if parent value 0 the parent is id team sub
My question :
how to know total childs from team (group head)? Or how to know the bottom child from id team? If I delete id team the child is deleted too..
example :
id team : 1
data from team_ sub :
status parent: 1 parent_id : 1 (id this data is 1)
status parent: 0 parent_id : 1 (id this data is 2)
status parent: 0 parent_id : 2 (id this data is 3)
status parent: 0 parent_id : 3 (id this data is 4)
status parent: 0 parent_id : 4 (id this data is 5)
id team : 2
data from team_ sub :
status parent: 1 parent_id : 2 (id this data is 6)
status parent: 0 parent_id : 6 (id this data is 7)
status parent: 0 parent_id : 7 (id this data is 8)
status parent: 0 parent_id : 8 (id this data is 9)
status parent: 0 parent_id : 9 (id this data is 10)

where parent status is 1 , parent_id is id team..
where parent status is 0, parent_id is id team_sub..
this is relation data on image

sorry if my english is bad…
id team_sub 10 is child from id team 2 and id team_sub 5 is child from id team 1..
can’t check it right now, but should be like this if I understood you right :
It selects every entry that is technicaly part of the parent_id =1 aka part of the sub_team
If you just want a number of entrys that have this condition :
exaples:
I would recommend following structure:
In this way you can detemine the Team by “parent_id” and the head of the team by “parent”.
so in example like above:
By this you can Query any entry you want by simple determining the “parent_id” and “parent”
e.g.:
*FYI : if not yet any dependencies on the value-names, id recommend to rename “parent” to “head_of_team” and “parent_id” to “team_id”*