Home > Back-end >  What IsNull() means in the where clause?
What IsNull() means in the where clause?

Time:12-30

enter image description here

The product table is shown as above.

select * 
from product 
where isnull(product_description, null) = product_description

The SQL script is what I am trying to run.

Can I know how to read or what does it actually mean for the conditions? Why the row 4 is not selected? Feel like the query is same as

select * 
from product 
where product_description is not null

I am a little bit confused about the conditions in the query.

CodePudding user response:

ISNULL takes in two arguments. It returns the first one unless it's null, in which case it returns the second argument - so writing something like ISNULL(SomethingHere, NULL) is meaningless - which means the where clause is the same as where product_description = product_description.

Since in T-SQL NULL = NULL returns UNKNOWN (which is equivalent to false in the context of a WHERE clause), it's basically the same as where product_description is not null.

  • Related