Why use laravel and write those ugly mysql queries? Why not use eloquent for it?
Jul 22, 2020
3
Level 9
How to get department head in query
I have three tables in mysql database: hr_employees, appraisal_goals and hr_departments
hr_departments have these fields:
'id',
'dept_name',
'dept_head'
SELECT DISTINCT e.employee_code, concat(e.first_name,' ',e.last_name) Fullname, e.email,
CASE
WHEN a.line_manager_mid_year_approved = 0 THEN "DRAFT"
WHEN a.line_manager_mid_year_approved = 1 THEN "AWAITING APPROVAL"
WHEN a.line_manager_mid_year_approved = 2 THEN "NOT APPROVED"
WHEN a.line_manager_mid_year_approved = 3 THEN "APPROVED"
ELSE "NOT STARTED"
END AS line_manager_mid_year_approved,d.dept_name
FROM hr_employees e
LEFT JOIN appraisal_goals a ON a.employee_id = e.id
INNER JOIN hr_departments d
ON e.department_id = d.id
WHERE e.company_id = 1
AND e.hr_status = 0
AND e.validation_status = 'VALID'
AND e.employee_type_code NOT IN (4,5);
I can get department head (employee first_name and last_name) when hr_departments.dept_head = hr_employees.employee_code
How do I complete this query to get department head?
Thanks
Please or to participate in this conversation.