SELECT `b` . `id` , `b` . `date_submitted` , `b` . `last_updated` , MAX ( `h` . `date_modified` ) AS `hist_update` , `b` . `status` FROM `mantis_bug_table` `b` LEFT JOIN `mantis_bug_history_table` `h` ON `b` . `id` = `h` . `bug_id` AND `h` . `type` = ? AND `h` . `field_name` = ? AND `b` . `date_submitted` <= `h` . `date_modified` WHERE `b` . `status` >= ? AND `h` . `new_value` >= ? AND `h` . `old_value` < ? AND `project_id` IN (...) AND `b` . `id` IN ( SELECT `mantis_bug_table` . `id` FROM `mantis_bug_table` JOIN `mantis_project_table` ON `mantis_project_table` . `id` = `mantis_bug_table` . `project_id` WHERE `mantis_project_table` . `enabled` = ? AND ( `mantis_bug_table` . `project_id` IN (...) ) ) GROUP BY `b` . `id` , `b` . `status` , `b` . `date_submitted` , `b` . `last_updated` ORDER BY `b` . `id` ASC 