【发布时间】:2021-06-07 20:29:02
【问题描述】:
假设如下数据库表:
帐户
| id | externalId | firstName | lastName |
|---|---|---|---|
| 4c8e49a6-b148-4125-9352-c2effda744b8 | null | Alan | Turing |
| 9bb67137-07cf-413b-8f7e-d710a9c52c19 | null | Bill | Gates |
| 7510fe8e-a976-4258-bf5a-a314373f6743 | 'abc' | Charles | Babbage |
| 62222be0-5e85-4333-9683-7b2de03073c5 | 'xyz' | Dennis | Richie |
以下查询返回以下结果:
SELECT TOP (1000) [id]
,[externalId]
,[firstName]
,[lastName]
FROM [ExampleDb].[dbo].[Accounts]
WHERE [externalId] != 'abc'
| id | externalId | firstName | lastName |
|---|---|---|---|
| 62222be0-5e85-4333-9683-7b2de03073c5 | 'xyz' | Dennis | Richie |
为什么此查询不返回 externalId 为 null (null != 'abc') 的行?
【问题讨论】:
-
没有“特殊情况”。这就是
NULL的定义方式以及它的永久定义方式。 -
你可以试试
null is distinct from 'abc'和null is not distinct from 'abc'
标签: sql