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?

How can we check for NULL in MySQL query?

WBOY
WBOYforward
2023-09-13 14:37:061203browse

我们如何在 MySQL 查询中检查 NULL?

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 -

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete