Use uma subconsulta:
DELETE FROM images
WHERE item_id NOT IN (
SELECT item_id FROM listings
);Isso remove imagens cujo item_id não aparece em listings. Em tabelas grandes, considere LEFT JOIN com IS NULL por desempenho.
Use uma subconsulta:
DELETE FROM images
WHERE item_id NOT IN (
SELECT item_id FROM listings
);Isso remove imagens cujo item_id não aparece em listings. Em tabelas grandes, considere LEFT JOIN com IS NULL por desempenho.