Sorry about that. Forgive me.
The difference between WHERE and HAVING is this.
WHERE limits the rows which will be COUNTed SUMmed, MAXed, or MINed.
HAVING limits the resulting summary rows.
Think of the GROUP BY query as producing a view or a temporary table based on the underlying tables. The HAVING clause works on this result, it can be based on any item in the SELECT list and nothing else.
The WHERE works on rows in the underlying tables and can use any columns or expression whether not they are in the SELECT list. The WHERE limits the rows which are summarized. The HAVING limits the summaries which are shown.
For example
Code:
SELECT state, COUNT(*)
FROM MyMailingList
WHERE zip BETWEEN '10101' AND '90210')
GROUP BY state
HAVING state LIKE 'new%'
will yield numbers for most of the 52 states since most zip codes are counted although a few areas might not be counted.
But the result of the HAVING clase will be to show only the counts for New York, New Mexico, etc.
You cannot simply reverse the role of zip and state. Partly because the HAVING clause may only have items from the SELECT list. More basic however is that the WHERE clause controls (filters) what is counted and the HAVING clause filters what is shown.