zoukankan      html  css  js  c++  java
  • Mysql Not in有null值查询的问题

    今天发现Mysql的not in使用的一个问题,大致是:

    select * from A where id not in (select fid from B).

    发现查询结果无论如何都是0条记录。后来发现B里面返回的查询结果集有一条NULL值,查了资料才知道mysql 的not in里面如果有一个NULL值,将返回0条记录。

    要解决这个问题需要把 select fid from B 变成

    select fid from B where B.fid is not null

    这个问题在其他的数据库里也会有,是因为 not in的处理有问题。再具体详细说明一下,如下:

    select * from A where id not in (1,2,null )

    那么就没有记录返回,因为里面有null值,当用id和null比较的时候,会返回false,所以一条记录都不会返回,所以要改成下面就可以了:

    select * from A where id not in (select bid from B where bid  is not null ) 
  • 相关阅读:
    Activator.CreateInstance 反射实例化对象
    MVC Form提交
    Redis 下载
    List<T> 序列化与反序列化
    快速反射DataTable
    数据库特性
    javascript判断文件大小
    MD5
    HttpHelper
    cacheHelper
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/5125546.html
Copyright © 2011-2022 走看看