Ok this is a bit more involved than I thought.-> Lookup all `ost_ticket` with `lastupdate < X` _(with “X” being the desired date-time stamp)_-> Loop through `ost_ticket` records and find all `ost_thread` records with `object_id` matching the `ost_ticket` record’s `id` and `WHERE object_type = T`-> Loop through `ost_thread` records and find all `ost_thread_entry` records with `thread_id` matching the `ost_thread` record’s `id`-> Loop through `ost_thread_entry` records and find all `ost_attachment` records with `object_id` matching the `thread_entry` record’s `id` and `WHERE object_type = H`-> Delete all matching `ost_attachment` recordsYou would keep the `ost_file` and `ost_file_chunk` records as a single file can be linked to multiple attachments. We only save the file once in the db (to save storage), and if someone uploads the same file again to another ticket, FAQ, etc. then we create a new attachment record linking back to the same file record…if, however, someone changes the file contents and uploads that then we save it as a new file record and link it to the new attachment record. Makes sense sort-of?After that, you could actually loop through all `ost_file` records and see if there are any `ost_attachment` records that `file_id` matches the `ost_file` record’s `id`…if none then he can delete the `ost_file` record and `ost_file_chunk` records where `file_id` matches the `ost_file` record’s `id`