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


在开发的过程中,遇到过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的数据的

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM