comaprison 运算符 (!=/<>) 的 MySQL 奇怪行为,即 NotEqualTo [英] MySQL strange behaviour for comaprison operator (!=/<>) i.e. NotEqualTo
问题描述
我使用简单的 WHERE
子句通过 NotEqualTo
比较从表中获取记录.具有讽刺意味的是,它不会返回列根本没有价值的记录.
I am using simple WHERE
clause to fetch records from a table using NotEqualTo
comparison. Ironically it doesn't return recrods where column has no value at all.
查询
SELECT * FROM TABLE WHERE COL<>'Something'
上面的查询将返回所有 COL 不等于东西的记录,但是,它不会返回那些 COL 为 empty 或 NULL 的记录.
Above query will return all records where COL isNotEqual to Something, however, It doesn't return those where COL is empty or NULL.
为什么会这样?
它应该返回 COL 为空/空的记录,因为它仍然满足它不等于 'Something' 的条件
It should return records where COL is empty/null as it still satisfies the condition that it isn't equal to 'Something'
推荐答案
检查 手册进行算术比较.
您不能使用算术比较运算符,例如 =、< 或 <>测试NULL.
You cannot use arithmetic comparison operators such as =, <, or <> to test for NULL.
这篇关于comaprison 运算符 (!=/<>) 的 MySQL 奇怪行为,即 NotEqualTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!