View Full Version : Combining HAVING and WHERE


Alexandre
10-31-2001, 06:27 AM
Could anybody explain me what is the use of using at the same time HAVING and WHERE for the same field in anSQL statment.

Example:
SELECT Table1.A, Table2.B,
FROM Table1, Table2
INNER JOIN Table1 on Table1.A = Table2.A
WHERE Table1.A 'Criteria1'
GROUP BY Table1.A, Table2.B
HAVING Table1.A 'Criteria2'

*Where I suppose that criteria1 and criteria2 arre valid criteria like = 1 or in ("a","b","c") etc

Seems to give the same result than
SELECT Table1.A, Table2.B,
FROM Table1, Table2
INNER JOIN Table1 on Table1.A = Table2.A
GROUP BY Table1.A, Table2.B
HAVING Table1.A 'Criteria2 AND Criteria1'

I could not see any difference on various examples. Of course it does not mean that there is no difference as a general rule. If anybody knows a counter-example or could explain the eventual difference in general terms, I would be grateful.

Alex

Pat Hartman
10-31-2001, 08:25 AM
The WHERE criteria is applied to the raw data. The HAVING is applied after the grouping is done.

Alexandre
10-31-2001, 08:57 AM
Thank you Pat

Alex