title: UPDATE table by INNER JOIN and where clause
body: <p><img src="https://i.stack.imgur.com/cv6Rp.jpg" alt="Tables"></p>
  
  <p>Got 2 tables as shown above. I want to update 'leaverecord.Consumed' from 'approved.Consumed' WHERE the leaverecord.name = approved.name and leaverecord.leavetype = approved.leavetype. Tried below query by getting <strong>error of 'Invalid use of group function</strong></p>
  
  <pre><code>UPDATE leaverecord r INNER JOIN approved a
  ON r.name = a.name
  SET r.Consumed = SUM(DATEDIFF(a.todate,a.fromdate))
  WHERE r.leavetype = a.leavetype AND
  r.name = a.name
  </code></pre>