may I ask for assistance regarding this code, getting different SUM() from different tables doesn't seem to work in this code. Apologies for this matter as I completely forgot how to do this anymore.
It only works when I only use sum for attendance query.
$sql = "SELECT *,
SUM(num_hr) AS total_hr,
attendance.employee_id AS empid,
employees.employee_id AS employee,
position.description AS job_description,
SUM(deductions.amount) AS total_amount_deduction
FROM attendance
LEFT JOIN employees ON employees.id=attendance.employee_id
LEFT JOIN position ON position.id=employees.position_id
LEFT JOIN deductions ON deductions.deduction_id=employees.deduction_id
WHERE date BETWEEN '$from' AND '$to'
GROUP BY attendance.employee_id
ORDER BY employees.lastname ASC, employees.firstname ASC";
I was hoping to get the results, but its showing different SUM values on every result.
When I remove SUM(deductions.amount) AS total_amount_deduction
and LEFT JOIN deductions ON deductions.deduction_id=employees.deduction_id
it works fine.