现在两个access表,表AAA和表BBB,且在两个表中同种商品ID值(文本型)是一样的,针对ID查询,现求:
1、表AAA中有,表BBB中没有的记录有哪些?
2、表BBB中有,表AAA中没有的记录有哪些?

解决方案 »

  1.   

    1. select a.* from 表AAA where Cast(ID as varchar(1000)) not in
       (select Cast(ID as varchar(1000)) from 表BBB)2.
      select a.* from 表BBB where Cast(ID as varchar(1000)) not in
       (select Cast(ID as varchar(1000)) from 表AAA)
      

  2.   

    select a.* from 表AAA where ID not in (selectID from 表BBB)
    select a.* from 表BBB where ID not in (select ID from 表AAA)
      

  3.   

    1、表AAA中有,表BBB中没有的记录有哪些?
    -------------------------------------
    select * from AAA where ID not in (select ID from BBB);
    2、表BBB中有,表AAA中没有的记录有哪些?
    -------------------------------------
    select * from BBB where ID not in (select ID from AAA);
      

  4.   

    id 不用是字符型也可以用 in
      

  5.   

    1:SELECT * FROM AAA WHERE ID NOT IN (SELECT ID FROM BBB)
    2:SELECT * FROM BBB WHERE ID NOT IN (SELECT ID FROM AAA)