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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:11:09+00:00 2026-06-12T02:11:09+00:00

I have the following two table scenario: users id groups 1 1,2,3 2 2,3

  • 0

I have the following two table scenario:

users
id   groups
1    1,2,3
2    2,3
3    1,3
4    3

and

groups
id
1
2
3

How do I return the IDs of all users that belong to group 2 and 1 for example? Should I look into join, a helper group_membership table or function to separate the comma delimited group IDs to get something like this:

group_membership
user_id   group_id
1         1
1         2
1         3
2         2
2         3
...       ...
  • 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-12T02:11:11+00:00Added an answer on June 12, 2026 at 2:11 am

    You should be having a many-to-many relationship between users and groups, (meaning, a user may belong into multiple groups, and a group can hold multiple users).

    You do that by having 3 tables:

    • users – to describe user information.
    • groups – to describe group information.
    • user_groups – to describe which users are in which groups.

    In the user_groups, you should have only 2 columns, user_id and group_id, each row is a single user belonging in a single group, where repititions on both sides are allowed.

    Your example translates into:

    user_id   group_id
    1         1
    1         2
    1         3
    2         2
    2         3
    3         1
    3         3
    4         3
    

    Then, it’s very easy to query all of the users in specific groups, as well as all of the groups as user is in.

    This process is also called Database Normalization

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

Sidebar

Related Questions

I have the following two table: -Groups- Id Name -Members- Id GroupId (Group.Id is
I have the following two tables in my mysql database. Table Name: groups id
I have the following scenario. I have two tables. One stores multi values that
i have the following query to list the employees of two table. i need
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3
I have two tables with the following (simplified) structures: table "Factors" which holds data
So I have two tables. Table 1 is named 'appointment' with the following fields:
I have the following two tables Groups Id (int) People Id (int) GroupId (int,
I have the following scenario: a Bitmap that is used as background and another
I have the following SQL problem. Scenario: I have two tables: Change and ChangeTicket.

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.