SQL中in和not in的问题

select count(*) from customer_info
where custcd not in (
select custcd from grade_model_info where custcd = '10000'
)
在这条Sql语句中grade_model_info这张表中事实上是没有custcd这个字段的,但是这个sql语句不会报错。会正常执行。但是把select custcd from grade_model_info where custcd = '10000'单独执行的话会报错。
还有一点就是custcd = '10000'这个限定条件中的值如果在customer_info表中存在记录,查询结果会有影响

qq_花开花谢_0
浏览 575回答 2
2回答

手掌心

整条语句 执行的话 “select custcd from grade_model_info where custcd = '10000'” 它 只是作为 “select count(*) from customer_info” 的条件存在 只会返回结果 为false或者空 所以 查询 不受影响 !
打开App,查看更多内容
随时随地看视频慕课网APP