SQL > SQL NULL > ISNULL Function

The ISNULL( ) function is available in SQL Server, MySQL, SparkSQL, and HiveQL. However, their uses are different:

ISNULL behaves differently across databases: SQL Server uses it to replace NULL with a specified value, while MySQL, SparkSQL, and HiveQL use it as a boolean test that returns 1 (or true) when the expression is NULL.

SQL Server

In SQL Server, the ISNULL( ) function is used to replace NULL value with another value.

For example, if we have the following table,

Table Sales_Data

 Store_Name  Sales 
Store A 300 
Store B NULL 

The following SQL,

SELECT SUM (ISNULL(Sales,100)) FROM Sales_Data;

returns the following result:

SUM (ISNULL(Sales,100))
400

This is because NULL has been replaced by 100 via the ISNULL function, so the total becomes 300 + 100 = 400.

MySQL

In MySQL, the ISNULL( ) function is used to test whether an expression is NULL. If the expression is NULL, this function returns 1. Otherwise, this function returns 0.

For example,

ISNULL(3*3) returns 0

ISNULL(3/0) returns 1

SparkSQL, HiveQL

In SparkSQL and HiveQL, the ISNULL( ) function is used to test whether an expression is NULL. If the expression is NULL, this function returns true. Otherwise, this function returns false.

For example,

ISNULL(3*3) returns false

ISNULL(3/0) returns true

Frequently Asked Questions

Q: What does ISNULL do in SQL Server?
A: In SQL Server, ISNULL(expression, replacement) replaces a NULL value with the specified replacement. If the expression is not NULL, it returns the expression unchanged.

Q: What does ISNULL do in MySQL?
A: In MySQL, ISNULL(expression) is a boolean test. It returns 1 if the expression is NULL, and 0 otherwise. It does not replace the NULL value.

Q: How does ISNULL differ between SQL Server and MySQL?
A: In SQL Server, ISNULL replaces NULL with a specified value. In MySQL, ISNULL is a boolean test returning 1 or 0. The behaviors are completely different.

Q: What is the equivalent of SQL Server ISNULL in MySQL or Oracle?
A: MySQL uses IFNULL() and Oracle uses NVL() to replace NULL values. COALESCE() is a standard SQL function that works across all major databases.

Next: SQL IFNULL Function

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact