I got it. The issue was that some users were not assigned to any group. I need 
them to show up either way: all users that do not belong to group 1, whether 
they belong to any other group or not. Apparently != does not count null (ie: 
no row found).

Here is what worked:

SELECT user.user_id 
FROM users user 
        LEFT JOIN users_groups usgr 
                ON usgr.usgr_user_id=user.user_id 
WHERE (usgr.usgr_grou_id!=1 OR usgr.usgr_group_id IS NULL) 
        AND user.user_status=1


On 2 Oct 2010, at 8:02, Wade Preston Shearer wrote:

> I have to be missing something simple here, but I am having trouble 
> formatting an MySQL query to select users that are not part of a group. I 
> have a users table, a groups table, and then a users-to-groups table.
> 
> 
> This query…
> 
> SELECT user.user_id 
> FROM users_groups usgr 
>       INNER JOIN users user 
>               ON usgr.usgr_user_id=user.user_id 
> WHERE usgr.usgr_grou_id=1 
>       AND user.user_status=1
> 
> 
> …gives me all the users in group 1.
> 
> 
> It then seems that this…
> 
> SELECT user.user_id 
> FROM users user 
>       LEFT JOIN users_groups usgr 
>               ON usgr.usgr_user_id=user.user_id 
> WHERE usgr.usgr_grou_id!=1 
>       AND user.user_status=1
> 
> 
> …should give me all users not in that group, but it doesn't work. What am I 
> missing?
> 
> _______________________________________________
> 
> UPHPU mailing list
> [email protected]
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net


_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to