bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

SQL HAVING Keyword

Concept visual

SQL HAVING Keyword

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

HAVING Keyword

Previous

❮ SQL Keywords

Next

Having

The HAVING

command is used instead of WHERE with aggregate functions. The following SQL lists the number of customers in each country. Only include countries with more than 5 customers:

Example

SELECT COUNT(CustomerID), Country

FROM Customers

GROUP BY Country

HAVING COUNT(CustomerID) > 5;
The following SQL lists the number of customers in each country, sorted high to low (Only include countries with more than 5 customers):

Example

SELECT COUNT(CustomerID), Country

FROM Customers

GROUP BY Country

HAVING COUNT(CustomerID)

> 5

ORDER BY COUNT(CustomerID) DESC;

Previous

❮ SQL Keywords

Next

Previous

SQL GROUP BY Keyword

Next

SQL IN Keyword