所以我的问题是' ON'如果人们从源表中删除,则子句将不符合删除条件。有没有办法在联合上进行外部联接以包括是否有任何内容被删除以使删除部分起作用?这件事将持续5分钟。对不起,如果这是我尝试做的一个不好的例子。
merge into table_one ab
using ( select people,job from table_jobs
where job = 'police'
union
select b.people,b.job from second_table_jobs b
where b.job = 'firefighter') zba
on (ab.people = zba.people)
update
set
ab.job ='firefighter'
where b.people = ab.people
and zba.job <> ab.job
delete where zba.people <> ab.people
when not matched then
insert
(
people,
job
)
values
(
zba.people,
zba.job
)
答案 0 :(得分:0)
您可以使用DELETE
运行单独的NOT EXISTS
语句,以保持其清洁。
DELETE FROM table_one ab
WHERE NOT EXISTS (SELECT 1
FROM (SELECT people,
job
FROM table_jobs
WHERE job = 'police'
UNION
SELECT b.people,
b.job
FROM second_table_jobs b
WHERE b.job = 'firefighter') zba
WHERE ab.people = zba.people);