I have three tables:
Table One: Users
Table Two: Roles
Table Three: UserInRoles
UserID | FullName
--------------------------------------------------
07DCEE4A-6598-42E1-95C6-0390FF8BB534 | John Doe
RoleID
---------------------------------------
E5C46F8E-EE6A-4052-AABA-08184E5F0158
UserID | RoleID
---------------------------------------------------------------------------
07DCEE4A-6598-42E1-95C6-0390FF8BB534 | E5C46F8E-EE6A-4052-AABA-08184E5F0158
I need to Select all UsersID
who's not in table UserInRoles
from table Users
I tryed :
SELECT DISTINCT Users.UserId, Users.FullName
FROM Users
INNER JOIN UserInRoles
ON Users.UserId <> UserInRoles.UserId
To Select all UsersID who's not in table UserInRoles from table Users, simply use not in
select distinct * from users where userid not in
(select userid from UserInroles)