SELECT `a`.*, if(a.is_internal = 1, `d`.`name`, b.name) as customerName, `e`.`name` as `department_name`, `f`.`name` as `branch_name`
FROM `job` `a`
LEFT JOIN `customer` `b` ON `b`.`id` = `a`.`customerID`
LEFT JOIN company__department e ON e.id = a.departmentID
LEFT JOIN company__department d ON a.customerID = d.id
LEFT JOIN company__branch f ON f.id = e.branch_id
WHERE `a`.`ID` = '15'