I want to write a script which will show all messages owned by ONLY users with RoleID = 4. So I tried to write something like this:
SELECT DT.DiscussionThreadID, DT.Message FROM DiscussionThread DT
INNER JOIN Users U on U.UserID = DT.CreatedBy
INNER JOIN UserRoles UR on UR.UserID = U.RoleID
WHERE UR.RoleID = 4
Example of UserRoles table:
UserID RoleID
1 1
1 2
1 4
2 4
3 3
3 4
I expected to see only messages posted by user with UserID = 2 – he don’t have additional roles except of RoleID = 4. But my script returns all posts. Can someone help me?
1 Answer