Reputation: 21
I'm working on a project, I would like to know the difference between using is not null
or <> null
in Mysql.
Why should we use IS NOT NULL
instead of <> NULL
? For when I do as in the second case, no results are found.
Example
Select * from table where name is not NUll;
select * from table where name <> NUll;
Upvotes: 1
Views: 74
Reputation: 13394
From https://dev.mysql.com/doc/refman/8.0/en/problems-with-null.html:
In SQL, the NULL value is never true in comparison to any other value, even NULL. An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for the operators and functions involved in the expression.
NULL
values represent missing unknown data.
And NULL
values are treated differently from other values.
For NULL
values with comparison operators, such as =
, <
, or <>
is not possible to test for .
It's rule. So you only can use IS NULL
or IS NOT NULL
operators instead.
Upvotes: 3