当我使用 != NULL
或 IS NOT NULL
运行选择查询时,我得到不同的结果。
/** No results returned.*/
SELECT *
FROM PORT_INFO
WHERE PORT_CODE != NULL;
/** Results are returned.*/
SELECT *
FROM PORT_INFO
WHERE PORT_CODE IS NOT NULL;
- 在“我的表”中,PORT_CODE 列可为空。
- 列的类型为 VARCHAR(4)。
- MySql 版本 5.5.13 企业版。
最佳答案
来自documentation :
Because the result of any arithmetic comparison with NULL is also NULL, you cannot obtain any meaningful results from such comparisons.
所以基本上 IS NOT NULL
实际上会做你想做的事情,而 !=
不会做任何有用的事情(因为它也只会返回 NULL
>).
关于mysql - 在MySql中,!= NULL 和 IS NOT NULL 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17225491/