query “not equal” doesn't work

前端 未结 7 2092
时光说笑
时光说笑 2020-12-05 23:01

I have very simple query like this:

SELECT * FROM `all_conversations` WHERE `deleted_1` != \'1\';

And my deleted_1 be default

相关标签:
7条回答
  • 2020-12-06 00:03

    Can you try this: deleted_1 is not null and deleted_1 != '1'?

    mysql> select 0 is not null and 0 != '1', 1 is not null and 1 != '1', null is not null and null != '1';
    +----------------------------+----------------------------+----------------------------------+
    | 0 is not null and 0 != '1' | 1 is not null and 1 != '1' | null is not null and null != '1' |
    +----------------------------+----------------------------+----------------------------------+
    |                          1 |                          0 |                                0 |
    +----------------------------+----------------------------+----------------------------------+
    

    Or this deleted_1 is null or deleted_1 != '1':

    mysql> select 0 is null or 0 != '1', 1 is null or 1 != '1', null is null or null != '1';
    +-----------------------+-----------------------+-----------------------------+
    | 0 is null or 0 != '1' | 1 is null or 1 != '1' | null is null or null != '1' |
    +-----------------------+-----------------------+-----------------------------+
    |                     1 |                     0 |                           1 |
    +-----------------------+-----------------------+-----------------------------+
    

    It really depends on what you wanna get back.

    0 讨论(0)
提交回复
热议问题