Checking for an empty field with MySQL
Solution 1:
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.
Solution 2:
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)
Solution 3:
You could use
IFNULL(email, '') > ''
Solution 4:
There's a difference between an empty string (email != "") and NULL. NULL is null and an Empty string is something.