here’s an example of a SQL statement where we use HAVING:
select column1 from table1
where condition1
having condition2;
isn’t it the same exact thing if we do this:
select column1 from table1
where condition1 AND condition2;
what is the difference between these two?
In your example, they should do the same thing. But
WHEREgets processed before anyGROUP BY, and so it doesn’t have access to aggregated values (that is, the results ofMin(),Max(), etc. functions).HAVINGgets processed afterGROUP BYand so can be used to constrain the result set to only those with aggregated values that match a certain predicate.