title: Different SUM from different table in a single query
body: <p>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.</p>
  
  <p>It only works when I only use sum for attendance query.</p>
  
  <pre><code>$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";
  </code></pre>
  
  <p>I was hoping to get the results, but its showing different SUM values on every result.</p>
  
  <p>When I remove <code>SUM(deductions.amount) AS total_amount_deduction</code> and <code>LEFT JOIN deductions ON deductions.deduction_id=employees.deduction_id</code> it works fine.</p>