Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for an empty field with MySQL

Tags:

sql

php

null

mysql

People also ask

How do you check if a column is blank?

Re: Determine if column is empty The formula =COUNTA(A1:A100) will return the number of non-blank cells in the range A1:A100. So if this formula returns 0, the range A1:A100 is completely empty. Warning: a cell containing a formula counts as a non-blank cell, even if that formula returns the empty string "".

IS NULL check in MySQL?

To search for column values that are NULL , you cannot use an expr = NULL test. The following statement returns no rows, because expr = NULL is never true for any expression: mysql> SELECT * FROM my_table WHERE phone = NULL; To look for NULL values, you must use the IS NULL test.

Is Empty in SQL query?

The IS NULL condition is used in SQL to test for a NULL value. It returns TRUE if a NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

Is empty string NULL in MySQL?

In the above syntax, if you compare empty string( ' ') to empty string( ' '), the result will always be NULL.


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, '') > ''

There's a difference between an empty string (email != "") and NULL. NULL is null and an Empty string is something.


This will work but there is still the possibility of a null record being returned. Though you may be setting the email address to a string of length zero when you insert the record, you may still want to handle the case of a NULL email address getting into the system somehow.

     $aUsers=$this->readToArray('
     SELECT `userID` 
     FROM `users` 
     WHERE `userID` 
     IN(SELECT `userID`
               FROM `users_indvSettings`
               WHERE `indvSettingID`=5 AND `optionID`='.$time.')
     AND `email` != "" AND `email` IS NOT NULL
     ');