sql語句中使用in、not in 查詢時,注意條件范圍中的null值處理事項


emp表中的數據

 

 

1. 使用in的時候,忽略為null的,不會查詢出comm為null的數據

select * 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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM