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的数据的

原文地址:https://www.cnblogs.com/hongdada/p/5169255.html