Standard SQL boolean operator IS vs. equals (=) operator

前端 未结 2 1339
无人共我
无人共我 2020-12-09 16:41

On the Wikipedia page for SQL there are some truth tables about boolean logic in SQL. [1] The Wikipedia page seems to source the SQL:2003 standard.

The truth table f

相关标签:
2条回答
  • 2020-12-09 17:01

    As the above poster said, null = null is not correct. It will return NULL(false)

    For null comparison you must use IS NULL or IS NOT NULL.

    0 讨论(0)
  • 2020-12-09 17:03

    That's a new one for me.

    If I read that correctly the <boolean value expression> grammar defines three predicates solely for use with the boolean datatype IS TRUE, IS FALSE, IS UNKNOWN.

    These differ from their equality counterparts in that they only evaluate to True or False. Never to Unknown. i.e. UNKNOWN = TRUE would evaluate to UNKNOWN but UNKNOWN IS TRUE evaluates to False.

    The full truth tables for IS and = are below.

    +---------+-------+-------+---------+
    |   IS    | TRUE  | FALSE | UNKNOWN |
    +---------+-------+-------+---------+
    | TRUE    | TRUE  | FALSE | FALSE   |
    | FALSE   | FALSE | TRUE  | FALSE   |
    | UNKNOWN | FALSE | FALSE | TRUE    |
    +---------+-------+-------+---------+
    

    As opposed to

    +---------+---------+---------+---------+
    |    =    |  TRUE   |  FALSE  | UNKNOWN |
    +---------+---------+---------+---------+
    | TRUE    | TRUE    | FALSE   | UNKNOWN |
    | FALSE   | FALSE   | TRUE    | UNKNOWN |
    | UNKNOWN | UNKNOWN | UNKNOWN | UNKNOWN |
    +---------+---------+---------+---------+
    
    0 讨论(0)
提交回复
热议问题