-: Hi, guys, welcome back.
In this video I wanted to tell you real quick
about the HAVING clause.
It is used for filtering after aggregation.
So, the HAVING clause is used
for filtering after aggregation.
The WHERE clause is used for filtering before aggregation.
So if you wanted to do something like this,
SELECT poll_id and the COUNT of IDs,
FROM options, GROUP BY poll_id,
WHERE the option_count is greater than two.
Notice that here we're using the aggregation column
in the WHERE clause.
Then you're gonna get an error.
You can't do that.
The WHERE clause is only for filtering before aggregation.
You can do this though.
SELECT poll_id and COUNT of id AS option_count if you want,
FROM options, GROUP BY poll-id,
HAVING COUNT of id greater than two.
Something important to note here
is COUNT id does not run twice.
There's no performance problem here.
This is just the syntax used.
You can't use the alias column here,
but that's just simply how it's done.
But again, no performance problem there.
This is everything for this video.
Just wanted to tell you how HAVING and WHERE differ.
Thanks for joining me in this one.
Thank you for watching and I see you in the next one.