Here is your original Query:
select sum(sub_amt) total_due FROM
( SELECT sum(AmountGI) sub_amt
FROM generalinsurance
WHERE DatePaidGI is null union select sum(amount)
sub_amt from protection where DatePaid is null
union select sum(amount) sub_amt from buytolet where DatePaid is null
union select sum(amount) sub_amt from mortgage where DatePaid is null
union select sum(Commission) sub_amt from referrals where DatePaidReferral is null
union select sum(Commission) sub_amt from overseas where DatePaidOverseas is null )
You can see that you have an outer SELECT statement with a SUM, then inside you have a nested SELECT statement with a series of UNION SELECT statements. I think you would just want to use the nested SELECT when creating the pie chart, since that has the individual rows you would want plotted. The outser sum and select just gets the total of all of the rows and limits this query to returning only one result.


