What is the difference between “Is Not Null” and “Not Is Null”

后端 未结 3 1158
攒了一身酷
攒了一身酷 2021-02-02 08:49
SELECT id FROM customers WHERE type IS NOT Null;

Versus:

SELECT id FROM customers WHERE NOT type IS NULL;

The data th

3条回答
  •  隐瞒了意图╮
    2021-02-02 09:11

    IS NOT NULL is a comparison operator, just like IS NULL or =, >, <, etc.

    NOT is a logical operator that acts on the rest of the condition. So you can say NOT type = 5, NOT type IS NULL, or even NOT type IS NOT NULL.

    My point here is to point out that they are two very different operators, even though the result is the same. Of course, in boolean logic, there is no difference between NOT (column IS NULL) and column IS NOT NULL, but it's wise to know the difference.

    As for performance, IS NOT NULL might save you a few cycles over NOT ... IS NULL because you are using a single operator instead of two operators, but any reasonable optimizer will figure out they are the same thing before the query is run.

提交回复
热议问题