Here is standard SQL syntax for what you want to do:
delete from table2
where not exists (select 1
from table1
where table1.id = table2.id and
table2.date between table1."begin" and table1."end"
);
Do note that if an id
exists in table2
but not table1
, then all rows for that id
will be deleted.
This should be pretty efficient in most databases if you have an index on table1(id, date)
.