SQL > NULL

In SQL, NULL means that data does not exist. NULL does not equal to 0 or an empty string. Both 0 and empty string represent a value, while NULL has no value.

NULL in SQL represents the absence of a value — not zero and not an empty string. This distinction is critical because aggregate functions like AVG and COUNT exclude NULL rows, which can produce surprising results if you are not aware of it.

Any mathematical operations performed on NULL will result in NULL. For example,

10 + NULL = NULL

Aggregate functions such as SUM, COUNT, AVG, MAX, and MIN exclude NULL values. This is not likely to cause any issues for SUM, MAX, and MIN. However, this can lead to confusion with AVG and COUNT.

Let's take a look at the following example:

Table Sales_Data

 Store_Name  Sales 
 Store A 300 
 Store B 200 
 Store C 100 
 Store D NULL 

Below are the results for each aggregate function:

SELECT SUM(Sales), AVG(Sales), MAX(Sales), MIN(Sales), COUNT(Sales)
FROM Sales_Date; 

Result:

SUM(Sales) AVG(Sales) MAX(Sales) MIN(Sales) COUNT(Sales)
6002003001003

Note that the AVG function counts only 3 rows (the NULL row is excluded), so the average is 600 / 3 = 200, not 600 / 4 = 150. The COUNT function also ignores the NULL row, which is why COUNT (Sales) = 3.

Frequently Asked Questions

What does NULL mean in SQL?
In SQL, NULL means that data does not exist or is unknown. It is not the same as 0 or an empty string — both of those represent a value, while NULL represents the absence of any value.
How does NULL affect mathematical operations in SQL?
Any mathematical operation performed on NULL results in NULL. For example, 10 + NULL = NULL.
How do aggregate functions handle NULL values?
Aggregate functions such as SUM, COUNT, AVG, MAX, and MIN all exclude NULL values. This can cause unexpected results with AVG and COUNT — for example, AVG divides by the number of non-NULL rows, not the total number of rows.
How do I check for NULL values in a SQL query?
Use IS NULL or IS NOT NULL in your WHERE clause. For example: SELECT * FROM table WHERE column IS NULL.

Next: SQL ISNULL Function

This page was last updated on March 19, 2026.




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