SELECT `B` . `id` AS `bug_id` , COUNT ( `F` . `bug_id` ) AS `attachments` FROM `mantis_bug_table` `B` JOIN `mantis_bug_file_table` `F` ON ( `B` . `id` = `F` . `bug_id` ) WHERE `B` . `id` IN (...) GROUP BY `B` . `id` 