Database
" Without SQL, websites will never have any way to handle Databases for data. "

HAVING Clause

having clause is used with SQL Queries to give more precise condition for a statement. It is used to mention condition in Group based SQL functions, just like WHERE clause.

Syntax for having will be,

select column_name, function(column_name)
FROM table_name
WHERE column_name condition
GROUP BY column_name
HAVING function(column_name) condition

Example of HAVING Statement

Consider the following Sale table.

oidorder_nameprevious_balancecustomer
11ord12000Alex
12ord21000Adam
13ord32000Abhi
14ord41000Adam
15ord52000Alex

Suppose we want to find the customer whose previous_balance sum is more than 3000.

We will use the below SQL query,

SELECT *
from sale group customer
having sum(previous_balance) > 3000

Result will be,

oidorder_nameprevious_balancecustomer
11ord12000Alex