select * from 表1 where 书号 not in (select 书号 from 表2)
                            ~~~~~
没有记录是不是根本没有符合条件的记录啊.所以显示为空.而不是没有记录.

解决方案 »

  1.   

    1.
    select * from 表1
    结果几行
    2。
    select * from 表1 where 书号 in (select 书号 from 表2)
    结果几行
    3。
    select * from 表1 where 书号 not in (select 书号 from 表2)
    结果?
      

  2.   

    语法肯定没问题
    但最好不用子查询,
    用INNER JOIN select A.* from 表1 A INNEER  JOIN  表2 B ON A.书号=B.书号
    和LEFT JOIN 
    select A.* from 表1 A LEFT JOIN  表2 B ON A.书号=B.书号 WHERE B.书号 IS NULL
    效率肯定高
      

  3.   

    数据库什么版本?两个表的书号数据类型是不是不一样比如一个是char(10),一个是char(12),或者一个是char(10),一个是varchar(10)?试一下:
    select * from 表1 where rtrim(书号) not in (select rtrim(书号) from 表2)最后,不要用not in ,用not exists
      

  4.   

    1.not in 没问题,可以这样用效果和not exists一致
    2.这2个表的书号字段类型是否完全一致
    3.如果一致,那肯定是表1的数据全包括在表2中
      

  5.   

    select count(*) from 表1 where 书号 in (select 书号 from 表2)select count(*) from 表1是不是一样的??
      

  6.   

    除非你的 表2 里的书名有 null的值才会这样
    这个小bug微软已经知道了
      

  7.   

    select count(*) from 表1 where 书号 not in (select 书号 from 表2 where 书号 is not null)
      

  8.   

    --表1-表2
    select * from 表1 where not exists(select 1 from 表2 where 表1.书号=表2.书号)