Group By & Having
The GROUP BY statement groups rows with the same values into summary rows.
Its often used with aggregate functions (Count, Min, Max, Sum, Avg)
Simple Syntax:
Example:
How to find out the number of countries in the table
Does this result make sense?
What do you think about it now?
Group By Having
Having clause is used in SQL to filter Grouped data.
Wait.. if Where does filtering.. why need Having?
Let's learn more
Where clause filters on the entire dataset.
The Having clause filters on the grouped dataset.
Note: When Having is used without Group By, it acts like a Where clause. (this feature is available in current MySQL)
Last updated