MySQL-NULL安全NOT等于运算符

问题描述:

我很好奇.我知道NULL安全等于运算符< =>,但是是否存在一些NULL安全NOT等于运算符,或者我必须始终使用类似的东西:

I am just curious. I know about NULL safe equal operator <=>, but is there some NULL safe NOT equal operator, or I have to always use something like that:

(tab.id != 1 OR tab.id IS NULL)

或者有人喜欢

!(tab.id <=> 1)

COALESCE(tab.id, 0) != 1

如果愿意,可以在这里使用.我遍历参数,并返回不是NULL的第一个值.在这种情况下,如果它是NULL,它将比较0 != 1.尽管它可能会使用更多的符号,但在这种情况下,它仍然更易于管理,而不是被迫总是使用相反的布尔值"作为解决方案.

Can be used here if you like it. I goes through the parameters, and returns the first value that isn't NULL. In this case if it's NULL, it will compare 0 != 1. Although it may use more signs, it's still easier to manage instead of being forced to always have opposite "booleans" as a solution in those cases.

阅读 COALESCE()