SELECT `a`.*, `b`.`name` as `dept_name`, `c`.`name` as `period_from`, `d`.`name` as `period_to`, `e`.`status` as `leave_status`, `f`.`name` as `leave_type`, `f`.`colour`, `f`.`code`, `g`.`name` as `user_name`, `h`.`file_name`, `h`.`file_location`, `k`.`name` as `relief_person`
FROM `hr__leave_application` `a`
JOIN `company__department` `b` ON `b`.`id` = `a`.`department_id`
JOIN `hr__ref_leave_period` `c` ON `c`.`id` = `a`.`period_from_id`
JOIN `hr__ref_leave_period` `d` ON `d`.`id` = `a`.`period_to_id`
JOIN `hr__ref_leave_status` `e` ON `e`.`id` = `a`.`status`
JOIN `hr__leave_type` `f` ON `f`.`id` = `a`.`type_id`
JOIN `user` `g` ON `g`.`id` = `a`.`user_id`
LEFT JOIN `hr__leave_attachment` `h` ON `h`.`application_id` = `a`.`id`
LEFT JOIN `user__employment_detail` `i` ON `a`.`user_id` = `i`.`user_id`
LEFT JOIN `company__position` `j` ON `i`.`position_id` = `j`.`id`
JOIN `user` `k` ON `k`.`id` = `a`.`absent_relief_id`
WHERE `a`.`user_id` = '68'
AND `a`.`is_delete` =0
ORDER BY `a`.`status` ASC, `a`.`created_ts` DESC
 LIMIT 5