Well I think that query shouldn't be the hardest thing.. I would get the first post (postid) of any thread in this forum which has an attachment and then I try to find the attachments via the postid. If that attachment already has a thumbnail that thumbnail should be displayed
The question is: If I have more than one attachment in my database with the postid '5' how can I randomly choose between one of those with that postid so that I only get one randomly chosen attachment (despite the fact I may even have 3 or more attachments with the postid '5').