34,838
社区成员




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,3
insert 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)
*/
select * from Y except select * from X
SELECT * FROM Y
WHERE NOT EXISTS (
SELECT 1
FROM X
WHERE X.A = Y.A
AND X.B = Y.B
)