有两张表,表A内的某些记录在表B中是不存在的(注:两个表的结构一模一样)。
我想用查询语句返回存在差异的记录,怎么返回的记录数是0呢?
我用了以下语句:AdodcUnite.RecordSource = "select * from A where not exists (select * from B)"请大虾指点,谢谢

解决方案 »

  1.   

    "select * from A where not ID in (select ID from B)" 
      

  2.   

    根据2表的标识字段进行比较
    假设id字段是唯一的 可以把他作为标识字段
    select   *   from   A   where   not   exists   (select 1 from   B where a.id=b.id)
      

  3.   


    查询语句应该是这样写吧
    AdodcUnite.RecordSource="select * from A where not exists (select * from B where A.field1=B.field1)"
    field1为主键 
      

  4.   

    当然也可以写为这样
    "select * from A where field1 not in (select field1 from B)" 
      field1为主键 
      

  5.   

    我原来的问题描述得有点不对呢,
    现更改下:B不是一个实际存在的表,而是一个查询语句返回的结果集。
    即原来的语句为:"select * from  A  where  not  exists (select *  from B where B.ChildCode<>''"   这样就不能用到
    "select * from  A  where  not  exists (select *  from  B  where A.field1=B.field1)" 因我原来的子查询上已有条件语句 where  B.ChildCode<>''不知这种问题有没有办法解决?谢谢!
      

  6.   

    一样可以
    select   *   from     A     where     not     exists   (select   *     from   B   where   B.ChildCode <> '' and A.field1=B.field1)
    多了个条件而已