WEBVTT

1
00:00:00.400 --> 00:00:01.590
<v ->Hi, guys, welcome back.</v>

2
00:00:01.590 --> 00:00:03.350
In this video I wanted to tell you real quick

3
00:00:03.350 --> 00:00:06.230
about the HAVING clause.

4
00:00:06.230 --> 00:00:08.710
It is used for filtering after aggregation.

5
00:00:08.710 --> 00:00:09.960
So, the HAVING clause is used

6
00:00:09.960 --> 00:00:11.500
for filtering after aggregation.

7
00:00:11.500 --> 00:00:15.830
The WHERE clause is used for filtering before aggregation.

8
00:00:15.830 --> 00:00:17.930
So if you wanted to do something like this,

9
00:00:17.930 --> 00:00:21.380
SELECT poll_id and the COUNT of IDs,

10
00:00:21.380 --> 00:00:24.003
FROM options, GROUP BY poll_id,

11
00:00:24.003 --> 00:00:25.910
WHERE the option_count is greater than two.

12
00:00:25.910 --> 00:00:30.070
Notice that here we're using the aggregation column

13
00:00:30.070 --> 00:00:31.930
in the WHERE clause.

14
00:00:31.930 --> 00:00:33.330
Then you're gonna get an error.

15
00:00:33.330 --> 00:00:34.163
You can't do that.

16
00:00:34.163 --> 00:00:38.333
The WHERE clause is only for filtering before aggregation.

17
00:00:39.550 --> 00:00:41.030
You can do this though.

18
00:00:41.030 --> 00:00:44.960
SELECT poll_id and COUNT of id AS option_count if you want,

19
00:00:44.960 --> 00:00:46.500
FROM options, GROUP BY poll-id,

20
00:00:46.500 --> 00:00:49.123
HAVING COUNT of id greater than two.

21
00:00:50.210 --> 00:00:51.170
Something important to note here

22
00:00:51.170 --> 00:00:54.100
is COUNT id does not run twice.

23
00:00:54.100 --> 00:00:55.370
There's no performance problem here.

24
00:00:55.370 --> 00:00:56.800
This is just the syntax used.

25
00:00:56.800 --> 00:00:59.450
You can't use the alias column here,

26
00:00:59.450 --> 00:01:01.100
but that's just simply how it's done.

27
00:01:01.100 --> 00:01:03.203
But again, no performance problem there.

28
00:01:04.440 --> 00:01:05.690
This is everything for this video.

29
00:01:05.690 --> 00:01:09.460
Just wanted to tell you how HAVING and WHERE differ.

30
00:01:09.460 --> 00:01:10.660
Thanks for joining me in this one.

31
00:01:10.660 --> 00:01:13.310
Thank you for watching and I see you in the next one.

