SQL error on peter's SQL, MySQL doesn't like a.version_number in having clause, I've tried all the aliases I can think of:
Here is a dump of the table with real data, it might help:
DROP TABLE IF EXISTS `version`;
CREATE TABLE `version` (
`id` bigint(20) NOT NULL auto_increment,
`file_id`...