If what you say is correct, then I think you should be able to do something like this:
Code:
SELECT * FROM filedata LEFT JOIN attachment USING(filedataid) WHERE attachmentid IS NULL
(of course if you have a table prefix you need to add it to the table names). And you can change it to a DELETE if you're feeling confident.
But looking at the database, I find a filedataid field in tables filedata and attachment, but also in attachmentcategoryuser, picturecomment, and picturecomment_hash, and I don't know exactly what those are for, so I don't know if some filedata can be associated with something else without having an attachment record. If not, it seems like you'd at least want to remove those rows as well.