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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:24:37+00:00 2026-06-12T15:24:37+00:00

Hi there i have a table: Teams: as below |Team ID | Member ID|

  • 0

Hi there i have a table:

Teams: as below

|Team ID  | Member ID|
| 1       |  10       |
| 2       |  230      |
| 1       |  11       |
| 4       |  56       |
| 1       |  15       |
| 2       |  236      |
| 1       |  18       |
| 3       |  43       |
| 1       |  17       |

I did this to find the members of a team:

SELECT members from teams where team_ID = 1; and it gave me 10,11,15,18,17

I have a different table for each member .So I tried something like this to fetch the data from different tables and it worked fine:

SELECT * FROM 10
UNION ALL 
SELECT * FROM 11
UNION ALL 
SELECT * FROM 15
UNION ALL 
SELECT * FROM 18
UNION ALL 
SELECT * FROM 17

Is it possible to make this 2 Queries into 1 Query because the members of a team changes dynamically….

Any help please…

Let me be bit more clear: My final result should only contains data from different member tables. Hope I am clear..

  • 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-12T15:24:38+00:00Added an answer on June 12, 2026 at 3:24 pm

    First, I strongly advise that you consider a redesign of your table structure otherwise you will have a difficult time querying this data.

    You can do something like this though. Of course, this only works if you know the tables member tables that you want to query:

    select *
    from teams t
    left join
    (
      SELECT *, 10 Member 
      FROM 10
      UNION ALL 
      SELECT * , 11 Member 
      FROM 11
      UNION ALL 
      SELECT * , 15 Member 
      FROM 15
      UNION ALL 
      SELECT * , 18 Member 
      FROM 18
      UNION ALL 
      SELECT * , 17 Member 
      FROM 17
    ) m
      on t.memberid = m.member
    

    If you want to do this dynamically, then you might be able to use a prepared statement similar to this:

    SET @sql = NULL;
    SELECT
      GROUP_CONCAT(DISTINCT
        CONCAT(
          'select *, ',
          MemberID,
          ' AS Member from ', MemberID, '
           '
        )
      separator ' union all ') 
      INTO @sql
    FROM teams
    WHERE TeamID = 1;
    
    SET @sql = CONCAT('select *
                       from teams t 
                       left join
                       (', @sql, ' ) m
                         on t.memberid = m.member');
    
    -- select @sql
    
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table teams contains 1169 rows, 1133 from them have UserId field !=0. There is
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a table with many rows, is there any way to find out
I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot
I have table with around 70 000 rows. There is 6000 rows that i
I have problem with my application. I have table report, there are 2 column
I have a table where there is a column of type 'text'. I know
I have a table in which there are two columns : 1. import type,
I have users table. There are three other tables: developers, managers, testers. All of
I have a table that I created within xcode so there is no nib

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.