MERGE tb1 AS Target
USING (select f1,f2 from tb2) AS Source
ON (Target.[CAS_ID] = Source.f1 =target.f1
)
WHEN MATCHED THEN
UPDATE SET
Target.f2 = Source.f2
THEN NOT MATCHED BY TARGET THEN
INSERT (f1,f2)
VALUES (Source.f1,Source.f2)
WHEN NOT MATCHED BY SOURCE and (select id from tb3 where id in (1,2,3))
THEN DELETE
;
What is the issue in this table? I want to delete all rows that doesn't match and also those rows that are there in tb3.