在ACCESS中我有现个表,结构相同.现在我想查两个表中相同的和不同的记不录出来.在C# CommandText,中我输入
 select * from TableName  where checksum(*) in(select checksum(*) from  TempTable 查相同记录记录
 select * from TableName  where checksum(*) in(select checksum(*) from  TempTable 查不同记录.
结果报错:语法错误(操作符丢失)在表达式'checksum(*) in(select checksum(*) from  TempTable'中
请大家帮忙解决一下

解决方案 »

  1.   

    找出他们相同的记录
    select * from A Where id in (select id From B)
    select * from A where Exists (select 1 from B where id=a.id and col1=a.col1)
    select * from A inner Join B on a.id=b.id And a.col1=b.col1在表A中有的,在表B中没有的
    select * from A Where id not in (select id from B)
    Select * from A where not exists (select 1 From B where id=a.id and col1=a.col1)
    select * from A Left Join B on a.id=b.id and a.col1=b.col1 where b.id is null表B中有的,在表A中没有的
    select * From B where id not in (select id from A)
    select * from B where not EXISTS (select 1 from A where id=b.id and col1=b.col1)
    Select * from B left join A on a.id=b.id and a.col1=b.col1 where a.id IS null
      

  2.   

    ivan973 (湘平)
      '截至2010-11-30 23:12:59    正常结帖:0 
    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  4.   

    相同记录两个表做个inner join就行了。不同记录用 上边几楼的作法,not in ,然后,union 下
    select a,b from  tablea where (a,b) not in(select a,b from tableb)
    union
    select a,b from  tableb where (a,b) not in(select id from tableb)a,b是字段,换成你自己的。
    不知这种语法是否支持(oracel,db2都可以的)你需要试一试。
      

  5.   

    我的数据库是access 2003版
    如据如下 
    表A  
    户名     账号     金额
    张二     1001    50
    李四     1002    50
    王三     1003    20
    陈六     1004    30
    赵七     1005    40
    表B
    户名     账号     金额
    张广     1001    50
    李四     1023    50
    王三     1003    20
    陈得     1004    30
    赵七     1005    40相同结果
    王三     1003    20
    赵七     1005    40
    不同结果
    张二     1001    50
    张广     1001    50
    陈得     1004    30
    陈六     1004    30
    A,B表没有主键,即没有唯一标识字段所以用
    select * From B where id not in (select id from A)
    这样的就不行,因为只找ID 在两表中是不有相同或不同,如名字不同就找不出.
      

  6.   

    相同的记录
    select * from A 
    where 户名+', '+CStr(账号)+', '+CStr(金额) 
    in (select 户名+', '+CStr(账号)+', '+CStr(金额) from B)不同的记录
    select * from A 
    where 户名+', '+CStr(账号)+', '+CStr(金额) 
    not in (select 户名+', '+CStr(账号)+', '+CStr(金额) from B)
    union
    select * from B 
    where 户名+', '+CStr(账号)+', '+CStr(金额) 
    not in (select 户名+', '+CStr(账号)+', '+CStr(金额) from A)
      

  7.   

    相同的记录
    select A.* from A left join B 
    on A.户名=B.户名 and A.账号=B.账号 and A.金额=B.金额 where B.户名 is not null不同的记录
    select A.* from A left join B 
    on A.户名=B.户名 and A.账号=B.账号 and A.金额=B.金额 where B.户名 is null
    union
    select B.* from B left join A 
    on B.户名=A.户名 and B.账号=A.账号 and B.金额=A.金额 where A.户名 is null
      

  8.   

    貌似你少了半个括号'checksum(*) in(select checksum(*) from TempTable)'
      

  9.   

    ACCESS 中有 CStr()这个函数吗
      

  10.   

    建两个查询定义Q1:
    select 1 as t,fa.* from fa
    Q2:
    select 2 as t,fb.* from fb建第三个查询定义q3:select t,... from q1 union all select t,... from q2
    建第四个查询定义q4:select ...,count(distinct t) from q3 group by ...count(distinct t)的值>=2的是两个表重复的,=1是每个表所独有的.上面的...指的是具体字段名.
    Access有点特殊,超长的SQL必须保存为一个查询定义(QueryDef),所以,可以一条SQL语句搞不定.