This may be because the table user_roles
may be NULL user_id
when role_id
= 10
or role_id
= 12
.
The first query looks something like this:
SELECT COUNT(1)
FROM users
WHERE users.id NOT IN (id1, id2, id3, NULL, id4, NULL, id5,...)
users.id
, id , .
NULL, , NOT IN
users.id
[users.id
< > id1
AND users.id
< > id2
AND... users.id
< > NULL
users.id
< > id5
], , , SQL , users.id
< > NULL
, , FALSE , users.id
. users.id
users
, 0 .
FYI: id
= NULL
= > UNKNOWN, id
< > NULL
= > UNKNOWN, UNKNOWN TRUE, FALSE ( not TRUE
, , TRUE
), NULL
"" - .
, NULL , :
SELECT count(1)
FROM users
WHERE users.id NOT IN (
SELECT user_id as id
FROM users_roles as ur
WHERE
(ur.role_id = 10 OR ur.role_id = 12) AND ur.user_id IS NOT NULL
)
NOT IN
.
IN
, -NULL users.id
, , , 40 320 .