I’m doing a relatively simple mysql query:
SELECT g.id FROM myTable g
WHERE g.timestamp > '0'
AND g.userId = '1'
AND g.foo != '34'
ORDER BY g.id DESC LIMIT 0, 10
This query returns 0 rows, however if I remove the last condition, i.e change it to:
SELECT g.id FROM myTable g
WHERE g.timestamp > '0'
AND g.userId = '1'
ORDER BY g.id DESC LIMIT 0, 10
That returns 5-6 rows. This is very strange to me, since in all of those rows, the int column foo is set to NULL
What am I doing wrong?
Comparing something wilh
NULLwill result inunknown. That is whyNULLvalues have to be compared with theISoperator.Replace
with
or use the NULL-safe equality operator (thanks to eggyal):