SQLite select where empty?

后端 未结 4 484
春和景丽
春和景丽 2021-01-29 23:33

In SQLite, how can I select records where some_column is empty?
Empty counts as both NULL and \"\".

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 23:59

    It looks like you can simply do:

    SELECT * FROM your_table WHERE some_column IS NULL OR some_column = '';
    

    Test case:

    CREATE TABLE your_table (id int, some_column varchar(10));
    
    INSERT INTO your_table VALUES (1, NULL);
    INSERT INTO your_table VALUES (2, '');
    INSERT INTO your_table VALUES (3, 'test');
    INSERT INTO your_table VALUES (4, 'another test');
    INSERT INTO your_table VALUES (5, NULL);
    

    Result:

    SELECT id FROM your_table WHERE some_column IS NULL OR some_column = '';
    
    id        
    ----------
    1         
    2         
    5    
    

提交回复
热议问题