SELECT DISTINCTROW `mantis_bug_table` . * , CASE WHEN `NULLIF` ( `cf_alias_13` . `value` , ? ) IS NULL THEN ? ELSE ? END AS `cf_sortfield_13_null` , CAST ( `NULLIF` ( `cf_alias_13` . `value` , ? ) AS DECIMAL ) AS `cf_sortfield_13` FROM `mantis_bug_table` JOIN `mantis_project_table` ON `mantis_project_table` . `id` = `mantis_bug_table` . `project_id` LEFT OUTER JOIN `mantis_custom_field_string_table` `cf_alias_13` ON `mantis_bug_table` . `id` = `cf_alias_13` . `bug_id` AND `cf_alias_13` . `field_id` = ? WHERE `mantis_project_table` . `enabled` = ? AND ( `mantis_bug_table` . `project_id` IN (...) ) AND ( `mantis_bug_table` . `handler_id` = ? AND `mantis_bug_table` . `status` IN (...) ) ORDER BY `mantis_bug_table` . `sticky` DESC , `cf_sortfield_13_null` ASC , `cf_sortfield_13` DESC , `mantis_bug_table` . `last_updated` DESC , `mantis_bug_table` . `date_submitted` DESC LIMIT ?, ... 