I have a query that works fine when there is data but not when I have nothing in the charities table. Any help would be hugely appreciated.
SELECT C.CategoryId
, C.CategoryName
, ISNULL(COUNT(CC.CharityId), 0) as CharityCount
, C.IsDeleted
FROM Charity.Categories C
LEFT JOIN Charity.CharityCategories CC on C.CategoryId = CC.CategoryId
LEFT JOIN Charity.Charities CH ON CC.CharityId = CH.CharityId
WHERE CH.IsApproved = 1 and CH.IsDeleted = 0
GROUP BY C.CategoryId, C.CategoryName , C.IsDeleted
Order By C.CategoryName
I am basically trying to retrieve all of the available Charity.Categories with the counts of the approved and not deleted charities.