

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: What Are Aggregations?
incomplete
2: SUM
incomplete
3: MAX
incomplete
4: MIN
incomplete
5: GROUP BY
incomplete
6: Average
incomplete
7: HAVING
incomplete
8: HAVING vs. WHERE in SQL
incomplete
9: ROUND
incomplete
10: Query Practice – Average Ages
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
It's common for developers to get confused about the difference between the HAVING and WHERE clauses – they're pretty similar after all.
The difference, though, is straightforward enough:
WHERE condition is applied to all the data in a query before it's grouped by a GROUP BY clause.HAVING condition is applied only to the grouped rows that are returned after a GROUP BY is applied.This means that if you want to filter based on the result of an aggregation, you need to use HAVING. If you want to filter on a value that's present in the raw data, you should use a simple WHERE clause.
SELECT class_id, COUNT(id) AS class_size
FROM students
WHERE ...
GROUP BY class_id
HAVING ...