
- 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 to retrieve the corresponding value for NULL with a MySQL query?
For this, use IS NULL property. Let us first create a table −
mysql> create table DemoTable ( EmployeeName varchar(100), EmployeeAge int ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris',32); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('David',45); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Bob',NULL); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Sam',28); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Chris | 32 | | David | 45 | | Bob | NULL | | Sam | 28 | +--------------+-------------+ 4 rows in set (0.00 sec)
Retrieve the corresponding value for NULL −
mysql> select *from DemoTable where EmployeeAge IS NULL;
This will produce the following output −
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Bob | NULL | +--------------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL select query to fetch data with null value?
- Write a single MySQL query to return the ID from the corresponding row which is a NOT NULL value
- How to retrieve a value with MySQL count() having maximum upvote value?
- How can we check for NULL in a MySQL query?
- MySQL query to set values for NULL occurrence
- MySQL query to retrieve only the column values with special characters?
- MySQL query to fetch the maximum corresponding value from duplicate column values
- Write a single MySQL query to exclude a record and display NULL value
- How can I set 0 if a query returns a null value in MySQL?
- MySQL query to replace null value with empty string in several columns while fetching data
- Display the result with not null value first and then with null value in MySQL
- MySQL CONCAT a specific column value with the corresponding record
- MySQL query to make a date column NULL?
- How to find records with a null value in a set of columns with MySQL
- MySQL query to return the count of only NO values from corresponding column value

Advertisements