I have 2 tables
TYPES (ID, NAME)
SCHEDULE (ID, DATE, TYPE)
I want a query that returns the count of all the Types used in the schedule table for a given time period. Even if the count is zero.
I have:
Code:
SELECT TYPES.NAME, COUNT(SCHEDULE.TYPE)
FROM TYPES LEFT JOIN SCHEDULE ON SCHEDULE.TYPE = TYPES.ID
WHERE (SCHEDULE.DATE Between #1/1/2005 And #10/1/2005#)
GROUP BY TYPES.NAME
I can't get this query to return all the TYPES and their count. It only returns the TYPES/COUNT for the TYPES that fall within the time period of the WHERE clause.
If I re-write the query ommiting the WHERE clause
Code:
SELECT TYPES.TYPE, COUNT(SCHEDULE.TYPE)
FROM TYPES LEFT JOIN SCHEDULE ON SCHEDULE.TYPE = TYPES.ID
GROUP BY TYPES.TYPE
Then it works correctly. That is, the result looks something like
TYPE1 3
TYPE2 2
TYPE3 0
TYPE4 1
etc.
When I use the WHERE clause, then the result does not return the TYPES that have a count of 0.
Is there another way to write this query where I can specify a date range?
Thanks in advance