How to remove multiple records from one table based on the non-existence of a record in another table?
Two ways to accomplish that:

DELETE FROM details WHERE product_id NOT IN (SELECT id FROM products)


However, it is recommended to use left join:

DELETE details FROM details LEFT JOIN products ON details.product_id=products.id WHERE products.id IS NULL