SELECT DISTINCT a.*,uc.name AS uEditor,`#__mentoring_schools_2746931`.`name` AS schools_fk_value_2746931,`#__mentoring_programs_2745182`.`name` AS programs_fk_value_2745182,CONCAT(`#__mentoring_users_2745183`.`first_name`, ' ', `#__mentoring_users_2745183`.`middle_name`, ' ', `#__mentoring_users_2745183`.`last_name`) AS users_fk_value_2745183,CONCAT(`#__mentoring_users_2745185`.`first_name`, ' ', `#__mentoring_users_2745185`.`middle_name`, ' ', `#__mentoring_users_2745185`.`last_name`) AS users_fk_value_2745185,CONCAT(`#__mentoring_users_2745184`.`first_name`, ' ', `#__mentoring_users_2745184`.`middle_name`, ' ', `#__mentoring_users_2745184`.`last_name`) AS users_fk_value_2745184
FROM `#__mentoring_teams` AS a
LEFT JOIN #__users AS uc ON uc.id=a.checked_out
LEFT JOIN #__mentoring_schools AS #__mentoring_schools_2746931 ON #__mentoring_schools_2746931.`id` = a.`school`
LEFT JOIN #__mentoring_programs AS #__mentoring_programs_2745182 ON #__mentoring_programs_2745182.`id` = a.`program`
LEFT JOIN #__mentoring_users AS #__mentoring_users_2745183 ON #__mentoring_users_2745183.`id` = a.`mentor`
LEFT JOIN #__mentoring_users AS #__mentoring_users_2745185 ON #__mentoring_users_2745185.`id` = a.`smentor`
LEFT JOIN #__mentoring_users AS #__mentoring_users_2745184 ON #__mentoring_users_2745184.`id` = a.`mentee`
LEFT JOIN #__users AS created_by ON created_by.id = a.created_by
LEFT JOIN #__users AS modified_by ON modified_by.id = a.modified_by
LEFT JOIN #__mentoring_companies AS mc ON mc.id = #__mentoring_users_2745183.company
WHERE a.state = 1
ORDER BY #__mentoring_programs_2745182.`id` desc,#__mentoring_programs_2745182.name DESC,#__mentoring_schools_2746931.name ASC,#__mentoring_users_2745183.last_name DESC