select * from shopopened where productid not in (select productid from paper)两个表中的数据在上万条,shopopened表和paper是多对一的关系。
为什么上面的语句查询是空的(确认shopopened表中有paper表中不存在的值)

解决方案 »

  1.   

    两个表的productid 类型一样吗
      

  2.   

    另外 你确认shopopened表中有paper表中不存在的值还是你搞反了  应该paper表中有shopopened表中不存在的值
      

  3.   

    贴一条你认为符合条件的shopopened 中的记录.
      

  4.   

    检查字段类型是否一致
    select * from shopopened a 
    left join paper b on 
    a.productid=b.productid where b.productid is null
      

  5.   

    select * from shopopened a where not exists ( select 1 from paper b where a.productid=b.productid )
      

  6.   

    如果俩字段productid 不同的话根本就不存在外键连接这一说。
    先问一下两个表是否存在关联,即shopopened 中的productid 是否为外键????
      

  7.   

    select * from shopopened where productid not in (select productid from paper where productid  is not null )
      

  8.   


    这个问题在其他的数据库里也会有,是因为 not in的处理有问题。比如:select * from shopopened where productid not in (1,2,null )那么就没有记录返回,因为 里面有null值,而null什么都不 当用productid和null比较的时候,会返回false,所以一条记录都不会返回,所以要改成:select * from shopopened where productid not in (select productid from paper where productid  is not null )