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 8033131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:36:08+00:00 2026-06-05T01:36:08+00:00

Assume 2 tables: TABLE: team ———– | team_id | =========== | 1 | ———–

  • 0

Assume 2 tables:

TABLE: team
-----------
| team_id |
===========
| 1       |
-----------
| 2       |
-----------

TABLE: team_member
-------------------------------------------
| team_member_id | team_id | age | gender |
===========================================
| 1              | 1       | 20  | Male   |
-------------------------------------------
| 1              | 2       | 25  | Male   |
-------------------------------------------
| 1              | 2       | 23  | Female |
-------------------------------------------

How do I search for things like this:

  1. List of all teams that are only male, between ages of 18 and 25.
  2. List of all teams that are male and female, where either gender is between ages of 18 and 25.
  3. Etc.

I’m basically looking for general strategies on how to apply certain filters (e.g. age) across all the children records of team. Suggestions?

  • 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-05T01:36:09+00:00Added an answer on June 5, 2026 at 1:36 am

    team, team_member

    You can’t just apply a simple WHERE clause if you are checking for only an all male or all female team… it needs to be compared against the full set of team members. Try

    select 
          tm.team_id,
          sum( if( tm.gender = 'Male' AND tm.age between 18 and 25, 1, 0 )) as MaleInRange,
          count(*) AllTeamMembers
      from
          team_member tm
      group by
          tm.Team_ID
      having
          MaleInRange = AllTeamMembers
    

    Similarly, to ensure you have BOTH male AND female…

    select 
          tm.team_id,
          sum( if( tm.age between 18 and 25, 1, 0 )) as AgeInRange,
          sum( if( tm.gender = 'Male', 1, 0 )) as MaleCnt,
          sum( if( tm.gender = 'Female', 1, 0 )) as FemaleCnt,
          count(*) AllTeamMembers
      from
          team_member tm
      group by
          tm.Team_ID
      having
             AgeInRange = AllTeamMembers
         AND MaleCnt > 0
         AND FemaleCnt > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have two tables: Table MY_ENTITY ID: PK OTHER_ID: FK to table OTHER
Assume I have these tables, from which i need to display search results in
Assume I have a two tables, A and B. Table A has a primary
Assume I have 4 tables: Table 1: Task ID Task Schedule 1 Cut Grass
For the sake of simplicity, let's assume the following tables exist: Table 1 -
Assume that we've three tables Course - table ------------------ ID | CourseName ------------------ 1
Assume the following table structure: Tables: **Tasks** taskID int PK taskName varchar **Resources** resourceID
Assume the following tables: TABLE: foo ========================= | foo_id | fk_id | name |
Assume I have the following tables: TABLE: foo - foo_id (PK) TABLE: tag -
Let's assume I have the following table class: class TestTable(tables.Table): id = tables.Column() description

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.