I have a table of images, and those images will have various descendants such as thumbnails, different sized versions, and crops (and thumbs of those crops), etc.
This means each original image can potentially have quite a few descendants. These descendants are referenced by a parent_id field that gives the direct parent.
What is going to be the best, most efficient way to do this, as obviously selecting all children for each image / level and then deleting them is going to be pretty hefty if there is a batch image delete?
What you need to be looking at.. is cascading deletes.
This article from mysql website should help you out.
http://dev.mysql.com/tech-resources/articles/mysql-enforcing-foreign-keys.html