I am doing a query with a trivial join, with the intention of finding the newest record that the user hasn't voted on yet:
SELECT
v.user_id,
v.version_id,
vv.user_id
FROM versions v
LEFT JOIN versions_votes vv ON v.version_id = vv.version_id
WHERE vv.user_id != 39;
Curiously, this returns no rows if vv.user_id is null. My admittedly pedestrian understanding of the problem is that NULL cannot be equal to anything - that's why we have to test for IS NULL
rather than =NULL
in the first place.
And yet, here we are - and if I modify the WHERE clause as follows:
WHERE (vv.user_id != 39 OR vv.user_id IS NULL)
the query appears to work properly (and also appears to confirm that NULL
is evaluating to 39.