IsNull() 在 where 子句中意味着什么?
What IsNull() means in the where clause?
product_id
product_name
product_description
1
Fans
Panasonic fans
2
Refrigerator
Toshiba refrigerator
3
Light
Edison bulb
4
Laptop
NULL
商品table如上图
select *
from product
where isnull(product_description, null) = product_description
SQL 脚本是我正在尝试的运行。
我能知道如何阅读或它对条件的实际含义吗?为什么没有选择第 4 行?感觉查询和
一样
select *
from product
where product_description is not null
我对查询中的条件有点困惑。
ISNULL
接受两个参数。它 returns 第一个,除非它为空,在这种情况下它 returns 第二个参数 - 所以写类似 ISNULL(SomethingHere, NULL)
的东西是没有意义的 - 这意味着 where 子句与 where product_description = product_description
.
因为在 T-SQL NULL = NULL
returns UNKNOWN
中(相当于 false
在 WHERE
子句的上下文中), 与where product_description is not null
.
基本相同
product_id | product_name | product_description |
---|---|---|
1 | Fans | Panasonic fans |
2 | Refrigerator | Toshiba refrigerator |
3 | Light | Edison bulb |
4 | Laptop | NULL |
商品table如上图
select *
from product
where isnull(product_description, null) = product_description
SQL 脚本是我正在尝试的运行。
我能知道如何阅读或它对条件的实际含义吗?为什么没有选择第 4 行?感觉查询和
一样select *
from product
where product_description is not null
我对查询中的条件有点困惑。
ISNULL
接受两个参数。它 returns 第一个,除非它为空,在这种情况下它 returns 第二个参数 - 所以写类似 ISNULL(SomethingHere, NULL)
的东西是没有意义的 - 这意味着 where 子句与 where product_description = product_description
.
因为在 T-SQL NULL = NULL
returns UNKNOWN
中(相当于 false
在 WHERE
子句的上下文中), 与where product_description is not null
.