SQL Having

SQL Having

The SQL HAVING is typically used with a GROUP BY clause.
The HAVING is used to return records where aggregate values meet the specified conditions.

Having syntax

SELECT column_name1, column_name2, function(column_name1)
FROM table_name
GROUP BY column_name1, column_name2
HAVING function(column_name1) operator value

Having example

Coder books table

ID Title Price Description
1 Learn SQL 20 Learn SQL language
2 Learn MySQL 22 Learn MySQL language
3 HTML book 17 Learn HTML
4 Learn PHP 20 Introduction to PHP
5 Learn PHP 20 PHP course
SELECT price, count(price) p_count
FROM coder_books
GROUP BY price
HAVING count(*) > 0


Price p_count
17 1
20 3
22 1