有两个数据库acc1、acc2,都存有多条数据。现在想显示acc2中有但是acc1中没有的数据,而且acc2中数据可能有多条重复。同时显示在dbgrid中,如何显示?
因为是ACCESS数据库,子查询不能返回多个值。所以用
select * from acc2 where not exists (select * from acc1)。这个查询不能做到。

解决方案 »

  1.   

    给acc1,acc2建立主键  比如id
    然后
    select * from acc2 where id not exists (select id from acc1)
      

  2.   

    1 和主键没有关系
    2 你所说的数据是一个字段的还是所有字段的全部相同?
    Microsoft OLE DB Provider for SQL Server 错误 '80040e31' 超时已过期 /Expert/reply.asp,行105
      

  3.   

    acc2的字段acc1全部都有。但acc1还有一些acc2没有的字段。
      

  4.   

    可以用select * from acc2 where not exists(select * from acc1 where acc2.field1=acc1.field1 and acc2.field2=acc1.field2);
    也可以用select * from acc2 where id not in(select id from acc1);
      

  5.   


      可以用select  *  from  acc2  where  not  exists(select  *  from  acc1  where  acc2.field1=acc1.field1  and  acc2.field2=acc1.field2);  
    也可以用select  *  from  acc2  where  id  not  in(select  id  from  acc1);  
      

  6.   


      可以用select  *  from  acc2  where  not  exists(select  *  from  acc1  where  acc2.field1=acc1.field1  and  acc2.field2=acc1.field2);  
    也可以用select  *  from  acc2  where  id  not  in(select  id  from  acc1);  
      

  7.   


      可以用select  *  from  acc2  where  not  exists(select  *  from  acc1  where  acc2.field1=acc1.field1  and  acc2.field2=acc1.field2);  
    也可以用select  *  from  acc2  where  id  not  in(select  id  from  acc1);