1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

How do I structure a database to handle users in groups?




I’ve been working on a project that involves having a number of users. Each user can be in any number of predefined groups, and I’d like a user to only be able to see another user if they share at least one group.

Right now I have a table of users, and a table that has one column for each group, and one row for each user, and a boolean entry specifying whether the user is in the group. The problem is that this makes the query to determine whether a user can see another user is complicated, and if I want to add another group I have to change this query to account for the additional column.

Is there a better way to structure this in a relational database? (I’m currently using PostgreSQL , which I don’t think matters)


5 Responses to “How do I structure a database to handle users in groups?”

Leave a Reply

Spam Protection by WP-SpamFree

TigerDirect