select * from mubiao where item in (select item from producttest)这条语句,可以查询出来结果。但是,要是变成了select * from mubiao where item not in (select item from producttest)就查不出来任何结果了。为什么加了not,没有把item中没有的数据查找出来呢?

解决方案 »

  1.   

    呵呵,说明你mubiao表中的的item全部在producttest表中.
    not in 的意思是:item 不在(select)中
      

  2.   

    因为你的mubiao 里所有的item都在producttest里能找到啊。
      

  3.   

    CREATE TABLE #temp
    (
    item INT
    )
    INSERT #temp
    SELECT 1 UNION ALL
    SELECT 2 UNION ALL
    SELECT NULLCREATE TABLE #temp1
    (
    item INT
    )
    INSERT #temp1
    SELECT 1
    --自己体会一下吧,注意NULL的情况
    select * from #temp where item in (select item from #temp1)
    select * from #temp where item not in (select item from #temp1)
      

  4.   

    不是这样的,刚才忘了说了,我的mubiao 中,有7964条数据。用select in查询之后,只有7486条数据而已
      

  5.   

    是不是有null值影响?isnull()下
      

  6.   

    反正记录不多,建议LZ把那个In语句的执行结果排序输出到Excel表格中,再把mubiao表的全部记录也采用相同的排序规则并将结果输出到Excel表中,利用Excel的比较能力来检查到底缺了哪些记录
      

  7.   

    in是有结果的记录,而用了not in与in正好相反没有结果。
      

  8.   

    select count(*) from mubiao where isnull(item,0) in (select isnull(item,0)from producttest)看是否是7964条数据
      

  9.   

    因为是三值逻辑,不为true的时候 两种情况 为空 和 为false
      

  10.   


    是item 的值在mubiao 表中有多条吧。。
    7964-7486=478条select item  from mubiao group by item having count(*)>1;看看返回值是否478
      

  11.   

    是item 的值在mubiao 表中有多条重复的记录吧。。
    7964-7486=478条select item from mubiao group by item having count(*)>1;看看返回值是否478