MySQL - NULL safe NOT equal operator

前端 未结 4 815
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 06:58

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 this

4条回答
  •  鱼传尺愫
    2020-12-03 07:48

    COALESCE(tab.id, 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.

    Read documentation for COALESCE()

提交回复
热议问题