Having

SQL HAVING

HAVING is used in select similar like WHERE or when the state of a select uses an aggregate function.

Syntax

SELECT name_of_column, function(name_of_column)
FROM name_of_table
GROUP BY name_of_column
HAVING function(name_of_column) operator value

Example

Orders

IDNAMEPRICE
1Learn Python45
2MySQL Tutorial32
3PHP examples24
4Learn SQL32
2MySQL Tutorial32
SELECT id, name, SUM(price) as total 
FROM orders 
GROUP BY id, name
HAVING SUM(price) > 32;

Output

IDNAMETOTAL
1Learn Python45
2MySQL Tutorial64