我在一个表中有一个列,它可能包含空值或空值。我如何检查一个列是否为空或空的行中存在的表?

(e.g. null or '' or '  ' or '      ' and ...)

当前回答

写条件的一种更简短的方法:

WHERE some_col > ''

因为null > "会产生unknown,所以它会过滤掉空字符串和空字符串。

其他回答

下面的SQL查询工作正常。

SELECT * FROM <table-name> WHERE <column-name> IS NULL;

要么

SELECT IF(field1 IS NULL or field1 = '', 'empty', field1) as field1 from tablename

or

SELECT case when field1 IS NULL or field1 = ''
        then 'empty'
        else field1
   end as field1 from tablename

这句话对我来说更清晰更易读:

select * from my_table where ISNULL(NULLIF(some_col, ''));

获取包含NULL, 0, ", '', ''的行

    SELECT * FROM table WHERE some_col IS NOT TRUE;

获取没有NULL, 0, ", '', ''的行

    SELECT * FROM table WHERE some_col IS TRUE;

检查空值

$column is null
isnull($column)

检查是否为空

$column != ""

但是,你应该总是为列设置NOT NULL, mysql优化只能处理一个IS NULL级别