首页 > 数据库技术 > 详细

SQL 中 not in 查询不到数据问题

时间:2016-01-29 19:37:37      阅读:217      评论:0      收藏:0      [点我收藏+]

在开发的过程中,遇到过not in 始终查询不到数据问题

    select * from T_CustomerInfo where CustomerID not in (select CustomerID from T_OrderInfo)

后来使用not exists查询

select * from T_CustomerInfo a  where  not exists (select CustomerID from T_OrderInfo where CustomerID=a.CustomerID)

数据全部都查询出来了

查看数据,发现T_OrderInfo表中有一条数据中CustomerID为null

进行修改

select * from T_CustomerInfo where CustomerID not in (select isnull(CustomerID,NEWID()) from T_OrderInfo)

这个时候就可以查询出数据

可以发现not in 遇到null就无效了

 

对in进行调查

 select * from T_Task where ID in (select FlowID from T_TaskRecordDetail)

发现即使T_TaskRecordDetail中FlowID为null,也是可以查询出不为null的数据的

 

SQL 中 not in 查询不到数据问题

原文:http://www.cnblogs.com/hongdada/p/5169255.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!