In theory if you have users and groups, there is a possible design flaw, depending on the following:
- If a user can be in more than one group and group can have more than one user, in reality it is a many-to-many relationship that requires a table that, for example, group_ users, where the primary key of each one is inherited of them and generate 1: N and N: 1 relations, plus the columns that are desired.
The aforementioned scheme commonly applies to examples of schools, where there are students, subjects, classrooms, teachers, etc., and each table of the aforementioned generates N: N relations and it is necessary to convert them into 1: N relationships and / or N: 1 and naturally you can get the information without problem
Table users:
userId (Pk),
u.userName,
u.userEmail
... Other columns
Table groups:
groupId (Pk),
description
... Other columns
Table grups_users (breaks relationships N: N)
user.userId (Fk)
group.groupId / Fk)
... Other columns
In this way the entity-relationship design is normalized and queries are simpler
Select us.userId (Pk), us.userName, us.userEmail
From users us, groups_users gu
Where gu.groupId! = 1
I hope this helps.
Greetings !!!