🚨 Get Your Free NFT Certificate Mint by Completing the Web3 Exam! START NOW

Code has been added to clipboard!

Using the SQL ISNULL Function

Reading time 2 min
Published Aug 9, 2017
Updated Oct 10, 2019

SQL NULL Functions: Main Tips

  • The function ISNULL() is needed in order to define the way we use NULL.
  • There are other three functions which will produce a similar result ( COALESCE(), IFNULL(), NVL() ).

Syntax of SQL NULL

Below you can see the table "Products":

ID Name Supplier_ID Category_ID Unit Price Unit_In_Stock Unit_On_Order
1 Cucumber 3 3 5 crates 19 17 16
2 Tomato 3 3 6 crates 20 24 Null
3 Cheese 3 4 5 kg boxes 11 11 6
4 Milk 4 4 5 L bottles 22 56 12
5 Bread 4 4 36 boxes 26 26 1

Have in mind that UnitOnOrder has NULL values.

In the code example below we can see that the result will be NULL if the columns "Unit_On_Order" will contain NULL values:

SELECT Name, Price * (Unit_In_Stock + Unit_On_Order)
FROM Products

The examples below show that if the column "UnitOnOrder" is a value NULL the enumeration will proceed as usual. The function ISNULL() brings back a zero when NULL is the value:

MS Access

SELECT Name, Price * (Unit_In_Stock + IIF(ISNULL(Unit_On_Order), 0, Unit_On_Order))
FROM Products;
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
  • Easy to navigate
  • No technical issues
  • Seems to care about its users
Main Features
  • Huge variety of courses
  • 30-day refund policy
  • Free certificates of completion

SQL Server

SELECT Name, Price * (Unit_In_Stock + ISNULL(Unit_On_Order, 0))
FROM Products


Here we start using other functions rather than ISNULL() because of the database-system compatibility. In oracle we use the function NVL():

SELECT Name, Price * (Unit_In_Stock + NVL(Unit_On_Order, 0))
FROM Products


Just like in oracle, MySQL requires a different function to work. There are two that work:

First, we have the function IFNULL():

SELECT Name, Price * (Unit_In_Stock + IFNULL(Unit_On_Order, 0))
FROM Products

The second function is COALESCE():

SELECT Name, Price * (Unit_In_Stock + COALESCE(Unit_On_Order, 0))
FROM Products