not in mysql
时间: 2023-10-13 22:03:52 浏览: 103
在MySQL中,NOT IN用于查询不在某个值集中的数据。但是需要注意NULL值的处理。如果查询的字段值为NULL,NOT IN无法正常工作。例如,SELECT name, age FROM USER WHERE age NOT IN (12, 13)。如果有一个用户的age字段没有添加信息,即为NULL,那么这条数据无法被查询出来。如果想要查询age为NULL的数据,可以使用IFNULL函数进行判空处理。例如,SELECT name, age FROM USER WHERE IFNULL(age, '') NOT IN (12, 13)。这样就能够查询出age为NULL的数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [MySql中NOT IN使用时的注意事项](https://blog.csdn.net/jl15988/article/details/120505575)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [MySql如何使用not in实现优化](https://download.csdn.net/download/weixin_38723242/13683695)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]