John Smith John Smith - 4 years ago 94
SQL Question

Select all users NOT in the particular team

I want to select all users from the database that is not within the particular team ID I'm looking at. Trying to make an 'add a member' function which is supposed to list all members that are not in the active team.

I just can't seem to get the SQL right.. Either I get nothing, or I still get some members that are within the active team and others, which I don't want.

This is the database, IMGUR

So in this case, viewing team ID 77 on the website, I wanna see only "Admin", as he is the one member that is not within that particular team.

Any help would be much appreciated.

Answer Source

I think this is what you need:

WHERE userid NOT IN (
    SELECT userid
    FROM UserTeam
    WHERE teamid = ...

It returns all users except those in the specific team.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download