使用不存在:
Select b.PK1,b.PK2,b.PK3,b.PK4 --Primary key from BKP missed in CORE
from
(--select all PK existing in BKP
select
distinct
b.PK1,b.PK2,b.PK3,b.PK4 --Primary key from BKP
from BKP b) b
where not exists(select 1 from CORE c
where c.PK1=b.PK1
and c.PK2=b.PK2
and c.PK3=b.PK3
and c.PK4=b.PK4
)
使用左连接:
Select b.PK1,b.PK2,b.PK3,b.PK4 --Primary key from BKP missed in CORE
from
(--select all PK existing in BKP
select
distinct
b.PK1,b.PK2,b.PK3,b.PK4 --Primary key from BKP
from BKP b
) b
left join
(select c.PK1,c.PK2,c.PK3,c.PK4 --Primary key from CORE
from CORE c
) c
on c.PK1=b.PK1
and c.PK2=b.PK2
and c.PK3=b.PK3
and c.PK4=b.PK4
where c.PK1 is null --absent in CORE