本帖最后由 wxylvmnn 于 2013-02-06 11:04:29 编辑

解决方案 »

  1.   

    SELECT * FROM Y
    WHERE NOT EXISTS (
    SELECT 1
    FROM X
    WHERE X.A = Y.A
    AND X.B = Y.B
    )
      

  2.   


    select * from Y except select * from X
      

  3.   


    create table X(A int,B int constraint pk_x primary key(A,B))create table Y(A int,B int constraint pk_y primary key(A,B))insert into X(A,B)
     select 1,2 union all
     select 2,3insert into Y(A,B)
     select 1,2 union all
     select 1,3 union all
     select 2,1 union all
     select 2,2 union all
     select 2,3
    select Y.A,Y.B
     from Y
     left join X on Y.A=X.A and Y.B=X.B 
     where X.A is null and X.B is null/*
    A           B
    ----------- -----------
    1           3
    2           1
    2           2(3 row(s) affected)
    */