(NOT) INusually can be optimized with (NOT) EXISTS.
DELETE
FROM SLAVE_TABLE
WHERE NOT EXISTS (SELECT 1 FROM MASTER_TABLE M WHERE M.ITEM_ID = ITEM_ID)
I'm not sure what you are trying to do here, but for me this query indicates that you should use foreign keys to enforce such restrictions, and not run queries to clean up after that.
source
share