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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:56:24+00:00 2026-06-10T20:56:24+00:00

Suppose I have the following two tables in my MySQL database: Table 1:: EMP:

  • 0

Suppose I have the following two tables in my MySQL database:

Table 1:: EMP: EmpID, EmpName
eg. (1, 'John'), (2,'Alex'),(3,'Tom')

Table 2:: Team: TeamID, ManagerID, MemberID
eg. record1: (Team1, 1, 2), record2: (Team1, 1, 3) 

so there is a team with id team1, John is the manager and Alex and Tom are its members.

I want to display the records of the Team table on the screen in the following manner

| Team  | Manager | Members   |
| team1 | John    | Alex, Tom |

What should be SQL query which will join the above two tables and return me the names of the members when based on the memberIDs.

Also the result will be displayed as 1 row containing all the team members separated by a comma.

If there is a better way of designing these two tables then please suggest that also. It will be much appreciated.

Thanks.

  • 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-10T20:56:25+00:00Added an answer on June 10, 2026 at 8:56 pm

    I think you need to use GROUP_CONCAT. GROUP_CONCAT() function is used to concatenate column values into a single string. It is very useful if you would otherwise perform a lookup of many row and then concatenate them on the client end.

    SELECT  b.TeamID as TeamName, 
            a.EmpName as Manager,
            GROUP_CONCAT(c.EmpName) Members
    FROM    Emp a
                INNER JOIN Team b
                    ON a.EmpID = b.ManagerID
                INNER JOIN  Emp c
                    ON b.MemberID = c.EmpID
    GROUP BY b.TeamID, a.EmpName
    

    You can also change the separator, and the ordering

    GROUP_CONCAT( c.EmpName SEPARATOR '-' ),...
    GROUP_CONCAT( c.EmpName ORDER BY c.EmpName DESC ),...
    

    SQLFiddle Demo

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

Sidebar

Related Questions

Suppose I have the following two tables: STUDENT studentid lastname firstname 1 Smith John
Suppose we have a PostgreSQL database with two tables A, B. table A columns:
Suppose I have two tables Main and Other like the following: Main +----------+-----------------------------------+ |
Suppose I have two tables, table A and table B, and that table A
I use SQL Server 2000. Suppose I have two tables like the following: Area
Suppose I have following table in my database: Tbl_Persons: Id Country Name 1 Australia
Suppose I have the following MySQL table: user_id date_of_application date_ended grade status --------------------------------------------------------------- 1
Suppose I have a MySQL database named DB, and a table named ContactInfo. The
Suppose I have two tables Table1 and Table2 with the following data. Column1 Column2
suppose we have two tables users and products table users has an accountBalance column

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.