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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:05:52+00:00 2026-05-31T00:05:52+00:00

I have a number of user ID’s. I am inserting these into a group

  • 0

I have a number of user ID’s. I am inserting these into a group table which will contain a column for the user’s ID and the group ID. This will allow me to use the query “SELECT user_id FROM groups WHERE group_id = ‘3’;” to retrieve user ID’s of all the members of group 3.

My problem is that I currently have a list of all users IDs, which I got from a form, using the statements :

int i = 0;
String[] names = { Request.Form["usernames"]Split(' ') }; //retrieving names from form
List<int> user_ids = new List<int>();
foreach(string name in names){ 
    int user_id = db.QueryValue("SELECT user_id FROM users WHERE username = name");
    user_ids.Add(user_id); //now I have a list of all user_ids
}

I now wish to insert this data into the groups table, where all of the user_id values in the list will have the same group_ID. How can I do this?

//create a group from users
"INSERT INTO group (group_id, user_id) VALUES(?,?);
  • 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-31T00:05:53+00:00Added an answer on May 31, 2026 at 12:05 am

    What you are talking about is a many-many relationship. You already have a users table:

    **users**
    userid
    username
    

    You need an additional table in the middle. The group table will just have something like:

    **group***
    groupid
    groupName
    

    You would then have a table in the middle. This table would look something like this:

    **user_groups**
    userid
    groupid
    

    You could still use your code to insert a user,

    int i = 0;
    String[] names = { Request.Form["usernames"]Split(' ') }; //retrieving names from form
    List<int> user_ids = new List<int>();
    foreach(string name in names){ 
        int user_id = db.QueryValue("SELECT user_id FROM users WHERE username = name");
        user_ids.Add(user_id); //now I have a list of all user_ids
    }
    

    After this, you would insert a group:

    insert into group(groupName) values("Sample Group")
    

    Then you could retrieve the group id and use that to insert into user_groups

    select groupid from group where groupname="Sample Group"
    
    insert into user_groups(userid,groupid) values(...
    

    Also, the table structure should include primary keys and foreign keys (much like @sixlettervariables’ answer)

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

Sidebar

Related Questions

I have a WPF user control with a number of textboxes, this is hosted
I have a UI where the user enters a number into a text box,
I have a following table using MVC that shows number of items the user
I have a cell in which the user enters their name, a serial number
I have a large number of user IDs (integers), potentially millions. These users all
I have a number of spheres in 3d space which the user should be
I am new to android. I have a loginActivity which validates a user number
I have this query : INSERT INTO db1.outbox (DestinationNumber, TextDecoded) SELECT User.CellPhone, '$SMSMessage' as
I'd like to have a parent class (Group) where any number of User may
I have an ASP.NET web form which I am adding a variable number User

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.