SELECT `CFP` . `project_id` , `CF` . `id` FROM `mantis_custom_field_table` `CF` JOIN `mantis_custom_field_project_table` `CFP` ON `CFP` . `field_id` = `CF` . `id` WHERE `CFP` . `project_id` IN (...) ORDER BY `sequence` ASC , NAME ASC 