Looking for query, remove all record of child table where parent id not match with master record.
Master-Table
1. David
2. Fin
3. Lisa
Child-Table
1. 100
1. 200
2. 200
2. 222
8. 100
9. 100
Output Required on Child Table
1. 100
1. 200
2. 200
2. 222
want to remove record # 8 and 9 from child table, cuz it doesn’t have parent id.
Thanks
You can use an outer join in a
DELETEoperation:To prevent the need to do this, what you should look into are Referential CASCADE actions that execute whenever you delete a parent (row in the master table).
If you have an
ON DELETE CASCADEset up on the foreign key in your child table, any parent that gets deleted will also have all of its corresponding “children” deleted as well.