To search for column values that are NULL
, you cannot use an expr = NULL
test. The following statement returns no rows, because expr = NULL
is never true for any expression:
mysql> SELECT * FROM my_table WHERE phone = NULL;
以上是mysql官网描述:使用expr = NULL的表达示永远不可能为true;
官方的解决方法:
To help with NULL
handling, you can use the IS NULL and IS NOT NULL operators and the IFNULL() function.
使用IS NULL 、 IS NOT NULL和 IFNULL() 进行解决,要注意如果使用了索引,IS NOT NULL是不走索引的