By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table target (id int, code varchar(6));
insert into target (id, code) values
(1, 'ABC'),
(1, 'DEF'),
(1, 'IJK'),
(2, 'ABC'),
(2, 'XYZ');
create table source (id int, code varchar(6));
insert into source (id, code) values
(1, 'ABC'),
(1, 'DEF');
delete from target
where (id, code) in (
select t.id, t.code
from target t
left join source s on (s.id, s.code) = (t.id, t.code)
where s.id is null and t.id in (select id from source)
);
select * from target;
ID | CODE |
---|---|
1 | ABC |
1 | DEF |
2 | ABC |
2 | XYZ |