Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>can't check it right now, but should be like this if I understood you right :</p> <pre><code>SELECT * FROM Team_Sub WHERE (parent_id = 0) </code></pre> <p>It selects every entry that is technicaly part of the parent_id =1 aka part of the sub_team</p> <p>If you just want a number of entrys that have this condition :</p> <pre><code>SELECT COUNT(*) FROM Team_Sub WHERE (parent_id = 0) </code></pre> <p>exaples: </p> <pre><code>//Count all entries in Team_ID 1: SELECT COUNT(*) FROM Team_Sub WHERE (parent_id = 1) //Select all entrys in Team_ID 2: SELECT * FROM Team_Sub WHERE (parent_id = 2) //Count all Entries that do belong to an Team_ID: SELECT COUNT(*) FROM Team_Sub WHERE NOT (parent_id = 0) //Select all Entries that do belong to an Team_ID: SELECT * FROM Team_Sub WHERE NOT (parent_id = 0) </code></pre> <p>I would recommend following structure:</p> <pre><code>status parent: 1 parent_id : 2 (id this data is 6) status parent: 0 parent_id : 2 (id this data is 7) status parent: 0 parent_id : 2 (id this data is 8) status parent: 0 parent_id : 2 (id this data is 9) status parent: 0 parent_id : 2 (id this data is 10) </code></pre> <p>In this way you can detemine the Team by "parent_id" and the head of the team by "parent".</p> <p>so in example like above:</p> <pre><code>id 6 is Head of Team 2 id 7 is Subordinate of Team 2 id 8 is Subordinate of Team 2 id 9 is Subordinate of Team 2 id 10 is Subordinate of Team 2 </code></pre> <p>By this you can Query any entry you want by simple determining the "parent_id" and "parent"</p> <p>e.g.:</p> <pre><code>//Just Heads of any Team: SELECT * FROM Team_Sub WHERE (parent = 1) //Just Head of a specific team: SELECT * FROM Team_Sub WHERE (parent = 1) AND (parent_id="team id") //Just Subordinates of any Team: SELECT * FROM Team_Sub WHERE (parent = 0) //Just Subordinates of a specific team: SELECT * FROM Team_Sub WHERE (parent = 0) AND (parent_id="team id") //Just Anybody of a specific team: SELECT * FROM Team_Sub WHERE (parent_id="team id") </code></pre> <p>*<strong>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"*</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload