I have two SELECT statements that I'd like to sum. Both queries work fine but I'm not able to SUM the output of total. I tried following this question but unable to SUM by wrapping the query in select id, sum(amount) from ( )
SELECT "patient_profiles"."id", count(distinct recommendations.id) AS total
FROM "patient_profiles"
LEFT OUTER JOIN
"recommendations" ON "recommendations"."patient_profile_id" = "patient_profiles"."id"
GROUP BY "patient_profiles"."id"
UNION
SELECT "patient_profiles"."id", count(distinct patient_profile_potential_doctors.id) AS total
FROM "patient_profiles"
LEFT OUTER JOIN "patient_profile_potential_doctors" ON "patient_profile_potential_doctors"."patient_profile_id" = "patient_profiles"."id"
GROUP BY "patient_profiles"."id"