what's the difference between WHERE and HAVING
Solution 1
Explanation and query samples in this fine article: Where Vs Having / Difference between having and Where clause
Solution 2
You use "WHERE" clauses to select rows for inclusion in the dataset before grouping operations have happend (GROUP BY). You use HAVING clauses to filter rows after grouping.
So like if you're aggregating a sum or a maximum or a minimum, you can use HAVING predicates to check the aggregated values on the candidate rows.
Solution 3
There are some subtleties and intricacies, but quick description is a comparison: HAVING is to GROUP BY as WHERE is to SELECT.
In other words, if you think of HAVING as a WHERE clause that gets applied after the GROUP BY clause, things start to make sense.
Solution 4
You would use the Having statement with Group By, typically as a way to filter on an aggregate column.
You can get more information here.
Richard77
Updated on July 26, 2022Comments
-
Richard77 almost 2 years
It looks like both WHERE and HAVING help filter rows. I wonder if, instead of having to HAVING, I can use WHERE ... AND.
I'm a little confused.
Thanks for helping
-
Richard77 over 13 yearsSo you mean, the difference between the 2 is mostly the fact that one is applied to SELECT and the other to GROUP BY?