Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:32:29+00:00 2026-06-18T01:32:29+00:00

I have 2 tables: 1. Team id group_head initial_team id : for id table

  • 0

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) 

example on image

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
enter image description here

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..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:32:31+00:00Added an answer on June 18, 2026 at 1:32 am

    can’t check it right now, but should be like this if I understood you right :

    SELECT * FROM Team_Sub WHERE (parent_id = 0)
    

    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 :

    SELECT COUNT(*) FROM Team_Sub WHERE (parent_id = 0)
    

    exaples:

    //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)
    

    I would recommend following structure:

    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) 
    

    In this way you can detemine the Team by “parent_id” and the head of the team by “parent”.

    so in example like above:

    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
    

    By this you can Query any entry you want by simple determining the “parent_id” and “parent”

    e.g.:

    //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")
    

    *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”*

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two tables (simplified for this question): CREATE TABLE team (
I have some tables that benefit from many-to-many tables. For example the team table.
I have 3 tables like this player(id,name,age,teamid) team(id,name,sponsor,totalplayer,totalchampion,boss,joindate) playerdetail(id,playerid,position,number,allstar,joindate) I want to select teaminfo
I’m using SQL Server 2008. I have data as in this table: Team Email
I have 3 tables, team(id,name) player(id,teamid,name) playerdetail(id,playerid,height,weight), the relationship between team and player is
I have a table listing (gameid, playerid, team, max_minions) and I want to get
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
Suppose I have data in table X: id assign team ---------------------- 1 hunkim A
I have on table named players , then other tables named tries , conversions
I have two Oracle SQL Tables: Team and Work. I want to select all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.