Checking for an empty field with MySQL Checking for an empty field with MySQL sql sql

Checking for an empty field with MySQL


An empty field can be either an empty string or a NULL.

To handle both, use:

email > ''

which can benefit from the range access if you have lots of empty email record (both types) in your table.


Yes, what you are doing is correct. You are checking to make sure the email field is not an empty string. NULL means the data is missing. An empty string "" is a blank string with the length of 0.

You can add the null check also

AND (email != "" OR email IS NOT NULL)


You could use

IFNULL(email, '') > ''