in 不匹配 null 值,
EXISTS 匹配 null值。
下面的例子不能运行:
select count(*) from (select p5 from wgqtest where not EXISTS(select a.emp_code from base_employee a))
select count(*) from wgqtest where p5 in (select a.emp_code from base_employee a)
select count(*) from wgqtest where p5 not in (null)
select count(*) from wgqtest where p5 is not null
select a.emp_code from base_employee a where emp_code is null
select p5 from wgqtest
EXISTS 匹配 null值。
下面的例子不能运行:
select count(*) from (select p5 from wgqtest where not EXISTS(select a.emp_code from base_employee a))
select count(*) from wgqtest where p5 in (select a.emp_code from base_employee a)
select count(*) from wgqtest where p5 not in (null)
select count(*) from wgqtest where p5 is not null
select a.emp_code from base_employee a where emp_code is null
select p5 from wgqtest
本文探讨了SQL查询中IN与EXISTS关键字的区别,特别是当涉及到NULL值处理时的不同行为。通过具体的SQL示例,展示了如何正确使用这些关键字来避免查询错误。
261

被折叠的 条评论
为什么被折叠?



