I have the following queries:
SELECT count(*)
FROM User u
INNER JOIN NAME n
ON u.UserId = n.UserId
AND n.last = 'Joe';
--returns 1943
SELECT count(*)
FROM User u
WHERE u.UserId IN (
SELECT n.UserId
FROM NAME n
WHERE n.last = 'Joe'
);
--returns 1875
UserId is the primary key in table User, and a foreign key in table Name (not unique).
How come the join query returns more rows than the nested select query? Shouldn't they be the same?
Thanks.