×

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 Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 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 logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL FROM_BASE64() function

In this context, we will learn how we can use the MySQL FROM_BASE64()() function with proper syntax and good examples. Introduction of MySQL FROM_BASE64()() function Basically, the FROM_BASE64() function In MySQL decodes...

2 minutes read.

MySQL MAX function

The MAX function is a type of aggregation function that determines the maximum value of the table data. This function works on numerical data type values. If the table displays...

4 minutes read.

MySQL ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples. Introduction of MySQL ELT() function In the ELT function, the number field...

2 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL Data Types

Introduction of the Data types In the data file, we have several information such as names, numbers, marks, and other information. This information specifies categories such as numbers, characters, and decimal...

8 minutes read.

MySQL EXPORT_SET() function

In this context, we will learn how we can use the MySQL EXPORT_SET() function with proper syntax and good examples. Introduction of MySQL EXPORT_SET() function This function returns a string and shows...

3 minutes read.

MySQL Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL LOAD_FILE() function

In this context, we will learn how we can use the MySQL LOAD_FILE() function with proper syntax and good examples. Introduction of MySQL LOAD_FILE() function The LOAD_FILE() function in MySQL reads a...

3 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 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 CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

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.

find_in_set() function in MySQL

This Function is used for finding the position of a particular string from the list of strings. For suppose if the specified string is repeated multiple times, then this functions...

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 CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.