Is Null Equal To Null



Is null equal to null?

No. null is not equal to null.

null is not nothing.

It is unknown.

An unknown value cannot be another unknown value.



Try this SQL code.

select "Codepedia" where null = null

Will that return any row. No.

Since both the values are unknown the condition cannot be true.



Try this.

select "Codepedia" where isnull(null,0) = isnull(null,0)

Will this return any row.

Yes!!!. It will return a row "Codepedia".

Why? Because we have specified in the code to replace both null values with 0(zero).

Since null is replaced with zero on both instances, 0 equals 0.

The condition is true and a row is returned.



Try this.

select "Codepedia" where isnull(null,1) = isnull(null,0)

Will this return a row.

No. It wont. Because the code will replace the first null with 1 and the second null with 0.

1 is not equal to 0.

The condition fails and no row is returned.