Click to See Complete Forum and Search --> : SQL statement.. Easy for gurus


HairyMonkeyMan
January 13th, 2006, 04:07 AM
Hi people :)

I have this sql statement:
SELECT Project_Category.*, COUNT(ProjectNo) AS ProjectCount
From Project_Category, Project
WHERE Project.[Project Category] = Project_Category.ProjectCategory
GROUP BY ProjectCategory, ProjectCategoryDesc
ORDER BY ProjectCategory

I am counting related records (i.e Projects within certain project categories). This code works, but does not show project categories with no related projects. Any ideas how to do this?

Thanks for your time :wave:

Vaderman
January 13th, 2006, 06:24 AM
You can use outer joins for this.
Outer Joins (http://www.devx.com/dbzone/Article/17403/0/page/4)

Regards

HairyMonkeyMan
January 13th, 2006, 06:55 AM
Thanks VaderMan

'LEFT JOIN' Fixed the problem.

My sql now looks like this:
SELECT Project_Category.*, COUNT(ProjectNo) AS ProjectCount
FROM Project_Category
LEFT JOIN Project ON Project_Category.ProjectCategory = Project.[Project Category]

GROUP BY ProjectCategory, ProjectCategoryDesc
ORDER BY ProjectCategory