博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL 中 not in 查询不到数据问题
阅读量:7020 次
发布时间:2019-06-28

本文共 585 字,大约阅读时间需要 1 分钟。

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

 

转载地址:http://ytbxl.baihongyu.com/

你可能感兴趣的文章