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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:39:31+00:00 2026-05-25T01:39:31+00:00

I have a little project and I have some SQL design issue with my

  • 0

I have a little project and I have some SQL design issue with my data.

Let say I have 2 table in my DB:

Contacts
ID
name
privateemail1
privateemail2
office email

and I have Groups

ID
Groupname

What is the best way to link together them for distributions list that I would be able to use Groups in Groups as well?

If I do a members table with

ID
GroupID
ContactID

I can’t see how to fit the embedded subgroups to the main.

Groups such as

Main groups e.g. Orchestra players; Singers
Sub groups e.g. Wind players, String players, male singers, female singers etc.

Revised question: the examples above can’t cover all the variations… any groups can become sub or main, like Outlook Distribution list?

Just looking the comments, which I am very grateful, it would be nice to be able to see an CREATE, SELECT with all the groups and a DELETE example. That would bring more attention and hopefully more result.

I hope it isn’t too dummy question but as a beginner I have spent some hours before I post this… Thanks for the helps in advance

  • 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-25T01:39:31+00:00Added an answer on May 25, 2026 at 1:39 am

    I’ve solved this with a dual-use table:

    Table:groupMemberships

    id
    groupID
    linktype
    linkID
    

    linktype can either be a text field (‘user’,’group’) which is nice and readable (if you’re doing your own SQL access it may be worth the small performance hit) or you could use an INT field where (1,2) where each mean something to you.

    To find all users in group 2:

    SELECT linkID as userID FROM groupMemberships 
    WHERE groupID=2 AND linktype='user';
    

    To find all sub-groups:

    SELECT linkID as groupID FROM groupMemberships 
    WHERE groupID=2 AND linktype='group';
    

    One of the problems with a dual table like this is when you want to -say- get all group users, but you have no idea how many sub-groups their might be. If you can be sure there’ll only be one level of sub-groups you can do:

    SELECT linkID as userID FROM groupMemberships
    WHERE groupID=2 and linktype='user'
    UNION
    SELECT sg.linkID as userID FROM groupMemberships g,groupMemberships sg
    WHERE g.groupID=2 AND g.linktype='group' 
      AND sg.groupID=g.linkID AND sg.linktype='user'
    

    If you have two tiers of sub-group, you’d need two unions and so on. When you have n sub groups you need N unions which is a pain to write and not efficient.

    An alternative solution is to keep your contacts and groups tables the same, and simply link contacts to groups – table contactsGroups

    ID
    groupID
    userID
    

    Now code side (outside of the database) when you add a user to a group (windplayers) you also add them to any parent groups (orchestra) automatically so the user actually gets two entries in the contactsGroups table. This has the same stored information, but makes data-retrieval much easier. You can even store this sub-group information in the database, although you already have it code-side with object inheritance or similar.

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

Sidebar

Related Questions

I have a little project with some jsp deployed on an Tomcat 5.5. Recently
I need some advice on a little project im doing. I have a database
I have a little Android project going on which involves some IPC where client
I'm working on a little project, basically I have some text on my PHP/HTML
(By the way, I don't use Interface Builder) I have a little project consisting
I have a little pet web app project I'd like to show someone who
I have a little private Google code project. For a SCM I use Mercurial.
So I have a little bit of a problem. I working on a project
I've started working on a little ruby project that will have sample implementations of
I’m having a little Architecture problem. In my project I have a Business Logic

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.