In SQL, a comparison between a null value and any other value (including another null) using a comparison operator (eg =, !=, <, etc) will result in a null, which is considered as false for the purposes of a where clause (strictly speaking, it's "not true", rather than "false", but the effect is the same).

The reasoning is that a null means "unknown", so the result of any comparison to a null is also "unknown". So you'll get no hit on rows by coding where my_column = null.

SQL provides the special syntax for testing if a column is null, via is null and is not null, which is a special condition to test for a null (or not a null).

Here's some SQL showing a variety of conditions and and their effect as per above.

create table t (x int, y int);
insert into t values (null, null), (null, 1), (1, 1);

select 'x = null' as test , x, y from t where x = null
union all
select 'x != null', x, y from t where x != null
union all
select 'not (x = null)', x, y from t where not (x = null)
union all
select 'x = y', x, y from t where x = y
union all
select 'not (x = y)', x, y from t where not (x = y);

returns only 1 row (as expected):

TEST    X   Y
x = y   1   1

See this running on SQLFiddle

Answer from Bohemian on Stack Overflow
🌐
W3Schools
w3schools.com › sql › sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
The IS NULL operator is used to test for empty values (NULL values). The following SQL lists all customers with a NULL value in the "Address" field:
🌐
Coginiti
coginiti.co › home › analysis › compare values when one is null
How to Compare Two Values in SQL When One Is Null - Coginiti
February 1, 2024 - SELECT * FROM your_table WHERE column1 = column2 OR (column1 IS NULL AND column2 IS NULL); In this example, the SQL statement checks if column1 is equal to column2 or both columns are null.
🌐
SQLTeam
forums.sqlteam.com › t › is-null-vs-null › 21223
IS NULL vs =NULL - SQLTeam.com Forums
June 15, 2022 - How can the below return different things · NULL is an unknown value and therefore a NULL value can never be equal to another value, even if that other value is NULL. NULL = NULL is unknown and cannot be true - eliminating that row from the ...
🌐
CastorDoc
castordoc.com › how-to › how-to-use-equal-null-in-sql-server
How to use EQUAL NULL in SQL Server?
Now that we have a good grasp of NULL in SQL Server, let's dive into the syntax of the EQUAL NULL operator. The EQUAL NULL operator is used to compare a column value to NULL, allowing us to filter records based on their NULL values.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › language-elements › null-and-unknown-transact-sql
NULL and UNKNOWN (Transact-SQL) - SQL Server | Microsoft Learn
Applies to: SQL Server Azure SQL ... the value is unknown. A null value is different from an empty or zero value. No two null values are equal....
🌐
Quora
quora.com › What-is-the-difference-between-“is-null”-and-“-null”-in-SQL
What is the difference between “is null” and “= null” in SQL? - Quora
Answer (1 of 10): It's important to note, that NULL doesn't equal NULL. [code ]NULL[/code] is not a value, and therefore cannot be compared to another value. [code ]where x is null[/code] checks whether x is a null value.
Find elsewhere
Top answer
1 of 7
40

It's convenient for the way SQL is typically used. Consider this statements:

SELECT people.name, cars.model FROM people
INNER JOIN cars
    ON people.car_licenceplate = cars.licenceplate

If null = null, then this would return all pairs of people with no license plate with all unregistered cars in the database, a usually undesirable result.

It's particularly convenient that, even if you use any null value even in a more complex expression, you won't get a value back, even if other values may also happen to be null. In other languages you'd need to null check everything in advance to get that behavior, having it by default is very convenient for the type of things SQL is typically used for.

null in SQL is exempt from a lot of other rules too. For example they are excluded from unique constraints. All indicating it represents more the absence of a value rather than a special value.

Some other languages do also have a ThreeValueBoolean or a similar type that behaves more like a SQL null, though only for booleans. Also most every language has similar non self-equality for NaN. It's not a concept unique to SQL.

2 of 7
23

One way to look at this is to compare these two questions:

  1. Is value A definitely the same as value B?
  2. Is value A definitely different from value B?

On the face of it, these are symmetrical: if question 1 is true, question 2 is false, and vice versa.

But what if both A and B are missing or invalid data points?

  1. False. We can't know for sure that the two missing or invalid data points are the same.
  2. False. We can't know for sure that the two missing or invalid data points are different.

That puts us in a peculiar position: A = B and A <> B should both be false, but that means that NOT (A = B) is no longer the same as A <> B, which is surprising.

SQL handles this by returning a further NULL - if the data for A and B is missing, then the information about whether they are the same or different is also missing. This is consistent with other operations on NULL, e.g. NULL + NULL is NULL, because adding two unknown numbers gives you a third unknown number. And since that also includes boolean negation - if A is NULL, then NOT A is also NULL, the result of NOT (A = B) is always the same as A <> B, as we'd intuitively expect.

However, there are situations where we want to ask the strict negation of those questions:

  1. Is value A not definitely the same as value B? (Strict inverse of question 1)
  2. Is value A not definitely different from value B? (Strict inverse of question 2)

For these, SQL provides the DISTINCT FROM and NOT DISTINCT FROM operators.

More commonly, you want to know explicitly that a particular value is or is not null, for which there are the operators IS NULL and IS NOT NULL.

🌐
LearnSQL.com
learnsql.com › blog › null-comparison-operators
How to Use Comparison Operators with NULLs in SQL | LearnSQL.com
Guess how many rows it returns: SELECT spouse FROM simpsons WHERE spouse = NULL OR NOT (spouse = NULL) ... Whatever the comparison column contains – salaries, pet names, etc. – if we test that it is equal to NULL, the result is unknown.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › queries › is-null-transact-sql
IS NULL (Transact-SQL) - SQL Server | Microsoft Learn
To determine whether an expression is NULL, use IS NULL or IS NOT NULL instead of comparison operators (such as = or !=). Comparison operators return UNKNOWN when either or both arguments are NULL.
🌐
Modern SQL
modern-sql.com › feature › is-distinct-from
Modern SQL: IS DISTINCT FROM — A comparison operator that treats two NULL values as the same
In SQL null is not equal (=) to anything—not even to another null. According to the three-valued logic of SQL, the result of null = null is not true but unknown.
🌐
Wikipedia
en.wikipedia.org › wiki › Null_(SQL)
Null (SQL) - Wikipedia
January 7, 2026 - Other SQL operations, clauses, and keywords using the "not distinct" definition in their treatment of Nulls include: The PARTITION BY clause of the ranking and windowing functions such as ROW_NUMBER · The UNION, INTERSECT, and EXCEPT operators, which treat NULLs as the same for row comparison/elimination purposes ... The principle that Nulls are not equal to each other (but rather that the result is Unknown) is effectively violated in the SQL specification for the UNION operator, which does identify nulls with each other.
🌐
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › equal_null
EQUAL_NULL | Snowflake Documentation
Compares whether two expressions are equal. The function is NULL-safe, meaning it treats NULLs as known values for comparing equality.
🌐
Upscale Analytics
ramkedem.com › home › sql server is null operator
SQL Server IS NULL Operator - Upscale Analytics
September 9, 2020 - In SQL Server, to handle comparison with NULL values, you need to use the following SQL Server operators: IS NULL – equals the operation ‘= NULL’ (records with NULL values)
🌐
Coginiti
coginiti.co › home › beginner › sql is null
What is the IS NULL Operator in SQL? - Coginiti
September 25, 2023 - The SQL IS NULL is an operator that tests for NULL (or empty) values in a column.
🌐
ThoughtSpot
thoughtspot.com › sql-tutorial › sql-is-null
SQL IS NULL | Basic SQL | ThoughtSpot
November 18, 2025 - This SQL tutorial covers how to work with null values by using SQL's IS NULL operator to select rows where a column contains no data.
🌐
MSSQLTips
mssqltips.com › home › null safe equality in sql server
NULL Safe Equality in SQL Server
June 17, 2025 - Unlike other SQL dialects (like SparkSQL or PostgreSQL’s <=> operator), T-SQL treats NULL comparisons uniquely: NULL = NULL doesn’t evaluate to TRUE, nor does NULL != NULL evaluate to FALSE; both yield UNKNOWN. This behavior creates a persistent challenge when comparing two values, ensuring they are considered “equal” if both are NULL, and “not equal” if one is NULL and the other is not.