Select*fromEmployeeWHERESalaryISNULL;+----+-------+--------+|ID|Name | Salary|+----+-------+--------+|7 |Aryan|NULL ||8"/> Select*fromEmployeeWHERESalaryISNULL;+----+-------+--------+|ID|Name | Salary|+----+-------+--------+|7 |Aryan|NULL ||8">
Home >Database >Mysql Tutorial >How can we check for NULL in MySQL query?
With the help of IS NULL operator, we can check for NULL in MySQL queries. We cannot use = (comparison operator) because we know that NULL is not a value. The following example using data from the "Employees" table will demonstrate it -
mysql> Select * from Employee WHERE Salary IS NULL; +----+-------+--------+ | ID | Name | Salary | +----+-------+--------+ | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+-------+--------+ 2 rows in set (0.00 sec)
The above query uses the IS NULL operator and generates an output with NULL in the salary column.
mysql> Select * from employee where salary = NULL; Empty set (0.00 sec)
The above query uses = (comparison operator) and therefore produces an empty set because NULL is not a value.
The above is the detailed content of How can we check for NULL in MySQL query?. For more information, please follow other related articles on the PHP Chinese website!