×

MySQL ISNULL function

This function is used to check the null value in table data. It returns the result in a Boolean form. If table data is null, then the output becomes 1. If table data is not null, then the output becomes 0.

Syntax

The ISNULL function syntax shows below.

ISNULL (value);

MySQL ISNULL function with table syntax shows below.

Select * from table_name WHERE ISNULL (column name);

Prerequisite for the comparison function

  • Create table in the MySQL system using the below statement.
mysql> CREATE TABLE `marks` (
  `roll_no` INT NOT NULL,
  `name` VARCHAR(45) NULL,
  `physics` INT NULL,
  `chemistry` INT NULL,
  `maths` INT NULL,
  `english` INT NULL,
  PRIMARY KEY (`roll_no`));
  • Insert value in the table.
  • The output command shows the table format and its information.
mysql> Select * from marks;

Use of the ISNULL function

The following are the uses of the ISNULL function:

  • The ISNULL function compares the column data between null and not null values.
  • The ISNULL function uses to find out not null values in the table columns.
  • The ISNULL function returns the Boolean value (1 or 0) of the table columns.

Example of the "ISNULL" function

Example1: Execute the following query to know the working procedure of the "null" values and their output.

mysql> SELECT ISNULL(NULL);

OUTPUT

MySQL ISNULL function

The image shows the "1" value as output. It means the ISNULL function contains a null value in the table.

Example2: The "ISNULL" function with not null column example shows below.

mysql> SELECT ISNULL(20);

OUTPUT

MySQL ISNULL function

The image shows the "0" value as output. It means the ISNULL function contains not null value in the table.

Example3: The "ISNULL" function with table data example shows below.

mysql> select ISNULL(physics) AS subject  from marks;

OUTPUT

MySQL ISNULL function

The image shows the Boolean result of the given column. The "null" value columns display one (1) value. The "not null" value columns show zero (0) value.

Example4: The "ISNULL" function with the WHERE condition example shows below.

Execute the following query to understand the "ISNULL" statement with the WHERE clause. Here the ISNULL function applies to the single column of the table.

mysql> select ISNULL(physics) AS subject from marks where no > 2;

OUTPUT

Executing the query will return the following output where we see Boolean values 0 and 1.

MySQL ISNULL function

Example5: The "ISNULL" function with table data example shows below. Here the ISNULL function applies to the multiple columns of the table.

mysql> select ISNULL(physics), ISNULL(chemistry), ISNULL(maths), ISNULL(english) from marks ORDER BY physics ASC;

OUTPUT

Executing the below output Where we see the data is displayed in ascending order.

MySQL ISNULL function

Example6: The "ISNULL" function with the "WHERE" clause example shows below. Here, the "WHERE" clause applies to the physics column. The ISNULL function applies to the single column of the table.

mysql> select * from marks where ISNULL(physics);

OUTPUT

MySQL ISNULL function

The image shows null values physics column data. Here, you can see the last two rows of the table.


Related Topics

MySQL DAY() function

In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples. Introduction of MySQL DAY() function This function in MySQL is used to...

2 minutes read.

MySQL Environmental Setup

The MySQL Environmental Setup MySQL is free, open-source, and cross-platform software, which can be downloaded from its official website. MySQL management system installs on Linux, macOS, and windows. MySQL requires a framework...

6 minutes read.

MySQL Prefix index

Prefix index This index query creates an index column in the string or character column. MySQL system can create multiple indexes in the table. It will create in a table as...

3 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples. Introduction of MySQL SOUNDEX() function SOUNDEX() function in MySQL is used to...

3 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL POW() function

In this context, we will learn how we can use the MySQL POW() function with proper syntax and good examples. Introduction of MySQL POW() function This function in MySQL is used to...

2 minutes read.

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic...

6 minutes read.

MySQL String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL NATURAL JOIN

The natural join combines multiple tables using a column with the same name and data type. This operation combines a row of the two tables using common columns. This join...

4 minutes read.

MySQL Control flow function

The control flow function uses values or operands for logical operations. These functions can works on single and multiple conditions. The control flow function is based on the Boolean expression....

3 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL MONTHNAME() function

In this context, we will learn how we can use the MySQL MONTHNAME() Function with proper syntax and good examples. Introduction of MySQL MONTHNAME() function In MySQL the MONTHNAME() Function is used...

3 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL Constraints

MySQL Constraints Introduction The constraints help to restrict what values should be stored in a table. The constraints provide limitations of the columns or data. This function helps to insert data in...

20 minutes read.