使用 not in 加子查询的 查询语句,测试数据库 上好好的,线上项目查不出数据,
数据库数据是存在的
发现 问题出在 not in 后 有为null 的数据 所以没有数据返回 null什么都不能当 null 与ID进行匹配 返回 false
所以 一条数据也不会返回
原始sql
select * from xx where id not in (‘1’,’2’,null);
更改
select * from xx where id not in ( select * from xxx where id is not null );
解决使用NOT IN子查询时遇到的问题,当子查询中含有NULL值时会导致查询结果为空。通过调整查询逻辑,排除NULL值来确保正确返回结果。
1152

被折叠的 条评论
为什么被折叠?



