惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
T
Threatpost
G
Google Developers Blog
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
Hacker News: Ask HN
Hacker News: Ask HN
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Schneier on Security
B
Blog
V2EX - 技术
V2EX - 技术
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
Schneier on Security
Schneier on Security
F
Fortinet All Blogs
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
S
Security @ Cisco Blogs
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
Project Zero
Project Zero
I
Intezer
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
SecWiki News
SecWiki News
Martin Fowler
Martin Fowler

博客园 - hrx521

SQL用窗口函数做逐行累计的实用用例 我的蝶翼斑马鱼繁殖要领总结 如何从操作系统的角度,理解C#语言的Async Await 异步机制内部状态机的运行原理? C#扩展方法对软件工程构建的促进示例和总结 基于原数据库新创建一个带部分数据做为初始数据的数据库的思路 sql调优记录,不要在join on 条件中使用过多的条件 发布和更新自己的nuget包 Rust的枚举类型Enum Rust语言特色语法记录 Rustup-init.exe安装后执行cargo run 报错:`link.exe` returned an unexpected error的解决办法 FastReport.OpenSource .Net下开源免费报表打印组件 SQL使用Merge在一个语句中完成插入、更新和删除操作 IIS应用程序回收导致应用中Hangfire等后台任务无法正常启动工作的解决方法 Microsoft.AspNetCore.Identity 的使用记录 C# xml文档反序列化记事 债券与债券基金 Linq补充学习 Blazor学习记录_12._IIS部署_组件的引用_HTML元素的引用 Blazor学习记录_11.身份认证与授权 Blazor学习记录_10.C#和JS互操作_访问WEB API Blazor学习记录_9.预呈现_渲染树
SQL NOT IN 子查询存在 NULL 的经典行为陷阱--NULL 三值逻辑(TRUE / FALSE / UNKNOWN)
hrx521 · 2026-06-27 · via 博客园 - hrx521

现象:

select * from HouseInstrumentChaoBiao where id in(934601,934602) and id not in (select Inid from customer_account where Inid in(934601,934602))
查询结果是包含inid值为934601一个行;
但是当查询改为
select * from HouseInstrumentChaoBiao where id in(934601,934602) and id not in (select Inid from customer_account)
发现,查询没有结果行。
疑惑:按理说查询二的not in 子查询是包含范围更大的集合,但为什么偏偏没结果了呢?

解答:

原因是 表customer_account 的 Inid 字段存在至少一条 NULL 值,这是关键:
NOT IN (A,B,NULL) 逻辑等价于:
id <> A AND id <> B AND id <> NULL
SQL 中任何值 <> NULL 结果都是 UNKNOWN(未知)
WHERE 条件只接受 TRUE,整条判定整体变为 UNKNOWN,所有行都不匹配,最终无结果

补充:

为什么你会误以为是 SQL Server Bug
绝大多数开发不清楚 NULL 三值逻辑(TRUE / FALSE / UNKNOWN)
IN 不受子查询 NULL 影响,只有 NOT IN 会触发这个诡异空结果现象
该行为是 ANSI SQL 标准规定,不是数据库引擎缺陷,SQL Server 2008~2025 全部一致