I mostly have application development background. In programming languages variable == null or variable != null works.
When it comes to SQL, below queries don't give any syntax errors but don't return correct results either.
select SomeColumn from SomeTable where SomeNullableColumn=null
select SomeColumn from SomeTable where SomeNullableColumn<>null
Why do we need to write the queries with is null or is not null to get correct results?
select SomeColumn from SomeTable where SomeNullableColumn is null
select SomeColumn from SomeTable where SomeNullableColumn is not null
What's the reasons/requirements behind is null or is not null instead of =null or <>null?
Is this ANSI SQL or Microsoft's TSQL standard?
Because null is not equal to null, like NaN ("not a number" produced when, for example, 0 is divided by 0 or raised to the power of 0) is not equal to NaN. Consider null as an unknown value (an unknown value is not necessarily equal to some unknown value).
Because sql is based on set theory and predicate logic. This two strong mathematical foundations contains mathematical logic - Boolean algebra. In this logic exist three values - TRUE, FALSE and UNKNOWN (=NULL).
Is null is used instead of = null to separate logic. And why it is in ANSI standard? It is to make it more readable and separate three-valued logic.
In common datawarehouses is null replaced by '' to make qry more simple.
Or try SET ANSI_NULLS OFF option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With