I have a table with a lot of history entries that contain customer IDs.
There is a separate customer table. Occasionally some of the customer entries are removed.
delete from history_table where customer_id not in (select customer_id from customers)
did you mean something like this?