http://dev.mysql.com/doc/refman/5.0/en/problems-with-null.html
It states two facts:
* "In SQL, the
NULL
value is never true in comparison to any other value, even NULL."
* "To look for NULL
values, you must use the IS NULL
test." In other words, MySql provides special operators when dealing with NULL values. So if you were trying to perform a simple query like this:
SELECT id FROM users WHERE email = NULL
you would not get a syntax error. Instead, you just get an empty result returned by the query. Thanks, MySQL. (I sadly spent a good couple of hours tracking this exact problem). Instead, performing the query like this:
SELECT id FROM users WHERE email IS NULL
will yield the expected results. There is also IS NOT NULL, and a function IFNULL() to aid in your NULL comparisons. The documentation is a pretty good read, as mysql handles null quite differently then other languages.
Hopefully this will help save some innocent keyboards being destroyed out of frustration!