Home > Database > Mysql Tutorial > body text

How can we check for NULL in MySQL query?

WBOY
Release: 2023-09-13 14:37:06
forward
1175 people have browsed it

我们如何在 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template