Possible Duplicate:
what is “=null” and “ IS NULL”
Is there any difference between IS NULL and =NULL
What is the difference between
where x is null
and
where x = null
and why does the latter not work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In SQL, a comparison between a
nullvalue and any other value (including anothernull) using a comparison operator (eg=,!=,<, etc) will result in anull, which is considered asfalsefor the purposes of a where clause (strictly speaking, it’s “not true”, rather than “false”, but the effect is the same).The reasoning is that a
nullmeans “unknown”, so the result of any comparison to anullis also “unknown”. So you’ll get no hit on rows by codingwhere my_column = null.SQL provides the special syntax for testing if a column is
null, viais nullandis not null, which is a special condition to test for anull(or not anull).Here’s some SQL showing a variety of conditions and and their effect as per above.
returns only 1 row (as expected):
See this running on SQLFiddle