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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:55:25+00:00 2026-05-26T08:55:25+00:00

I have a table that stores user information in a table in a MySQL

  • 0

I have a table that stores user information in a table in a MySQL database. I need a way to store what classes those users are associated with.

Class as in… school.

The classes that are associated to the users needs to be dynamic and can be different for every user.

I was thinking of having a specific number of columns that are associated with classes in my user profile table. And then just insert a classId into a row if they are associated to the class. And just keep filling it up.

This seems dirty and really bad. What are my other options where I can query the database to know what classes a user is associated with?

  • 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-26T08:55:25+00:00Added an answer on May 26, 2026 at 8:55 am

    Set up two extra tables: one for classes (id, name, …) and an association table to associate users with their classes. The association table would have two columns: the user ID and the class ID. Then to get a user’s classes:

    select class_id
    from user_classes
    where user_id = X
    

    where X is the user’s ID. Similarly, to get the users in a class:

    select user_id
    from user_classes
    where class_id = X
    

    You’d probably want to set the PK for the association table to (user_id,class_id) and index each column individually.

    If you wanted more information about the class than just the ID, do a join:

    select u.name, ...
    from users u join user_classes uc on u.id = uc.user_id
    where uc.user_id = X
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ecommerce MySQL database that stores order information in the table 'orders'
I have a table called Users that stores generic user information (user id, first,
I have a table that stores user information. The table has a userid (identity)
I have a database table that stores document information (DocID, Name, Type, Owner, etc).
I have mysql table that has a column that stores xml as a string.
I have a table that functions as an event log and stores the users
Ok I have a table in my SQL Server database that stores comments. My
I have a webapp I'm making that stores user information, and their preferences regarding
I have a table that stores all the volunteers, and each volunteer will be
I have a table that stores various clients I have done work for, separated

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.