View Full Version : Delete records without matching records

Afrow UK
03-21-2007, 05:49 PM
I have a one to many relationship in my database.
I would like to delete records in one table if there are no matching records in another table.



03-21-2007, 06:22 PM
If you are using a version earlier then 4.0 you are out of luck..you will need to do it in a script.

If after 4.0 you could do something like

DELETE FROM table1 WHERE table1_id NOT IN (SELECT distinct table1_id FROM table2)

remember to do a dump before doing any mass deletes though...