UPDATE `comp_acc_det` a SET `a`.`amountdr` = (select SUM(amount_dr) from comp_journal_detail where companyID = a.companyID and acctCode = a.acctID and year = a.year and period=a.period and status=1 ), `a`.`amountcr` = (select SUM(amount_cr) from comp_journal_detail where companyID = a.companyID and acctCode = a.acctID and year = a.year and period=a.period and status=1 ), `a`.`total` = a.amountdr - a.amountcr, `a`.`updatedBy` = '2' WHERE `a`.`companyID` =  '3' AND `a`.`acctID` =  '59' AND `a`.`year` =  '2017' AND `a`.`period` =  '5'