You can use the WHERE clause to exclude rows that you do not need before executing GROUP BY.
SELECT p.spineinjuryAdmit, c.comorbidityexplanation, Count(c.comorbidityexplanation) AS CountOfcomorbidityexplanation FROM tblKentuckyCounties AS k INNER JOIN (tblComorbidity AS c INNER JOIN (Person AS p INNER JOIN tblComorbidityPerson AS cp ON p.PersonID = cp.personID) ON c.ID = cp.comorbidityFK) ON k.ID = p.County WHERE p.spineinjuryAdmit ALike "c%" GROUP BY p.spineinjuryAdmit, c.comorbidityexplanation
If your query is executed in SQL-89 mode, you can use this as a WHERE clause.
WHERE p.spineinjuryAdmit Like "c*"
In SQL-92 mode, you need a standard wild ANSI card.
WHERE p.spineinjuryAdmit Like "c%"
I used ALike to tell the database engine to expect wild ANSI cards.
SQL-89 mode is used by the DAO ... if you did not specify a database parameter to use SQL-92 mode ("SQL Server Compatible Syntax").
If you use a query with ADO, it will always use SQL-92 mode.
source share