当前位置:Gxlcms > 数据库问题 > sql语句中使用in、not in 查询时,注意条件范围中的null值处理事项

sql语句中使用in、not in 查询时,注意条件范围中的null值处理事项

时间:2021-07-01 10:21:17 帮助过:81人阅读

* from emp e where e.comm in (300, 500, null);

2. 使用not in的时候,如果 not in后面的选项中没有null,只会查询从comm列不为空的列中过滤,会过滤掉comm为null的数据

select * from emp e where e.comm not in (300, 500);

3. 使用not in 的时候,如果not in后面的选项中有null,不会查询出来任何数据。sql语句本身直接返回false,所以使用not in的时候,要保证in中的条件不会出现null的情况,不然可能会出现意想不到的情况。

select * from emp e where e.comm not in (300, 500, null);

 

sql语句中使用in、not in 查询时,注意条件范围中的null值处理事项

标签:忽略   info   使用   sql   not   png   http   处理   style   

人气教程排行