Either use
SELECT IF(field1 IS NULL or field1 = '', 'empty', field1) as field1
from tablename
or use the following code, which I copied from another answer (by Himanshu) to this same question, at https://stackoverflow.com/a/17833019/441757 —
SELECT case when field1 IS NULL or field1 = '' then 'empty' else field1 end as field1 from tablename
If you only want to check for null
and not for empty strings then you can also use ifnull()
or coalesce(field1, 'empty')
. But that is not suitable for empty strings.