How to return only unique values ​​in mysql

SELECT users.mail, users.name FROM members LEFT JOIN users ON (users.uid = members.uid) WHERE members.group = 27 AND members.uid NOT IN (SELECT subgroup_members.uid FROM subgroup_members LEFT JOIN subgroups ON (subgroups.id = subgroup_members.sid) LEFT JOIN users on (users.uid = subgroup_members.uid) WHERE subgroups.oid = 27 AND subgroup_members.leader = 1) 

This query returns all members of the group who are not leaders of the subgroup.

The participants table shows that userid(uid) belongs to group(group) , and the subgroup_members table shows which users belong to subgroup(sid) . Leadership is indicated by the symbol β€œ1” in the head column of the subgroup_members table.

I'm trying to figure out how to get back all the members of the group who are not the only leader of the subgroup, and now I'm pretty much a dead end.

So, instead of subgroup_members.leader = 1 I need to determine if this is the only value

+4
source share
1 answer

Take a look at using GROUP BY to highlight unique indexes.

Documentation : https://dev.mysql.com/doc/refman/5.5/en/group-by-modifiers.html

+1
source

All Articles