mysql not in 和 null的冲突

数据库users
id email cookie status
1 a@java-er.com aa 2
2 f@java-er.com bb null
3 b@java-er.com cc 1
4 d@java-er.com dd 3

select * from users where status not in (1,3)

第二条记录不出来

所以要改成

select * from users where (status not in (1,3) or status is null)

in不受影响

select * from users where status in (1,3)


This entry was posted in 数据库 and tagged . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/mysql-not-in-null/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

One Response to mysql not in 和 null的冲突

  1. 床垫品牌 says:

    为您带来全新五星睡眠体验,让健康与舒适日夜伴你左右。

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

  

About Me

静水流深,水滴石穿