表A(Code NVARCHAR(50),Name NVARCHAR(50))
数据为
A B
B C
C D
表B(Code NVARCHAR(50),Name NVARCHAR(50))
数据为
A B
B C
如何从A表中查询不在B表中的数据
既查出 A表中的行 C D 

解决方案 »

  1.   

    select * from 表A
    except
    select * from 表B
      

  2.   

    select * from 表A
    except
    select * from 表B
      

  3.   

    select * from 表A
    except
    select * from 表B
      

  4.   

    select * from a where checksum(*) not in(select checksum(*) from b)
      

  5.   

    另一種寫法,select a.*
    from 表A a
    left join 表B b
    on a.Code=b.Code and a.name=b.name
    where b.Code is null and b.name is null
      

  6.   

    补充:条件不是所有列
    表A(Code NVARCHAR(50),Name NVARCHAR(50),Re NVARCHAR(50))
    数据为
    A B 1
    B C 2
    C D 3
    表B(Code NVARCHAR(50),Name NVARCHAR(50),Re NVARCHAR(50))
    数据为
    A B 4
    B C 5
    如何从A表中查询Code和Name不在B表中的数据
    既查出 A表中的行 C D 3 
      

  7.   

    try this,select a.*
    from 表A a
    left join 表B b
    on a.Code=b.Code and a.name=b.name
    where b.Code is null and b.name is null
      

  8.   

    SELECT * FROM A 
    WHERE NOT EXISTS
    (
    SELECT * FROM B WHERE A.CODE=B.CODE AND A.NAME=B.NAME
    )