In order to remove orphan records from the database, we need to create a join on the parent and child tables and then remove the rows from the child table where id IS NULL-
DELETE PT FROM ParentTable PT LEFT JOIN ChildTable CT ON PT.ID = CT.ID WHERE PT.ID IS NULL