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

  • Home
  • SEARCH
  • 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 1039127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:03:40+00:00 2026-05-16T15:03:40+00:00

Newish to mysql DBs here. I have a table of USERS and a table

  • 0

Newish to mysql DBs here. I have a table of USERS and a table of TEAMS. A user can be on more then one team. What’s the best way to store the relationship between a user and what teams he’s on?

Lets say there are hundreds of teams, each team consists of about 20 users, and on average a user could be on about 10 teams, also note that users can change teams from time to time.

I can think of possibly adding a column to my TEAMS table which holds a list of user ids, but then i’d have to add a column to my USERS table which holds a list of team ids. Although this might be a solution it seems messy for updating membership. It seems like there might be a smarter way to handle this information… Like another table perhaps? Thoughts?

Thanks!

ps, whats the best field type for storing a list, and whats the best way to delimit?

  • 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-05-16T15:03:41+00:00Added an answer on May 16, 2026 at 3:03 pm

    whats the best field type for storing a list, and whats the best way to delimit?

    It’s usually a really bad idea to try to store multiple values in a single column. It’s hell to process and you’ll never get proper referential integrity.

    What you’re really looking for is a join table. For example:

    CREATE TABLE user_teams (
        user_id INT NOT NULL FOREIGN KEY REFERENCES users(id),
        team_id INT NOT NULL FOREIGN KEY REFERENCES teams(id),
        PRIMARY KEY (user_id, team_id)
    );
    

    so there can be any number of team_ids for one user and any number of user_ids for one team. (But the primary key ensures there aren’t duplicate mappings of the same user-and-team.)

    Then to select team details for a user you could say something like:

    SELECT teams.*
    FROM user_teams
    JOIN teams ON teams.id= user_teams.team_id
    WHERE user_teams.user_id= (...some id...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newish to mysql. I have a query and it is not showing the value
I'm newish to Python (and stackoverflow)...bear with me! I have a dictionary that looks
I'm newish to the python ecosystem, and have a question about module editing. I
I'm new here and a fairly newbish developer overall. I have looked online for
Newish C++ programmer here. I am creating a QT4 application and it's gotten large
I'm newish to NHibernate, and am attempting to wire up to a DB2 table
I'm newish to flex an have recently hit a snag casting. this is the
Hello I am newish to android dev, I am using Eclipse and I have
I'm newish to PHP and OOP and I have been using the PDO class
I am newish to Rails and i am facing a prblem. I have Models

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.