
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we check for NULL in a MySQL query?
With the help of IS NULL operator, we can check for NULL in a MySQL query. We cannot use = (comparison operator) because as we know that NULL is not a value. Following example using the data from ‘employee’ table will exhibit 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 query above use IS NULL operator and produces the output where salary column is having NULL.
mysql> Select * from employee where salary = NULL; Empty set (0.00 sec)
The query above use = (Comparison operator) hence produces the empty set because with NULL is not a value.
- Related Articles
- Can we use SELECT NULL statement in a MySQL query?
- Check for NULL or NOT NULL values in a column in MySQL
- How can I set 0 if a query returns a null value in MySQL?
- Can we use ORDER BY NULL in MySQL?
- What is MySQL LEFT JOIN and how can we write MySQL query for it?
- What is MySQL RIGHT JOIN and how can we write MySQL query for it?
- How can I return 0 for NULL in MySQL?
- How to retrieve the corresponding value for NULL with a MySQL query?
- How can we simulate the MySQL INTERSECT query?
- How can we simulate the MySQL MINUS query?
- MySQL query to set values for NULL occurrence
- How can we use a MySQL stored function in a database query?
- Can we use “LIKE concat()” in a MySQL query?
- Check for NULL or empty variable in a MySQL stored procedure
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?

Advertisements