MySQL HAVING Clause

In MSSQL, the HAVING clause is used to apply a filter on the result of GROUP BY based on the specified condition.
The where clause cannot perform filtering on aggregate expressions.

Syntax for HAVING Clause

SELECT column_1, function_name(column_2)
FROM tablename
WHERE condition
GROUP BY column_1, column_2
HAVING Condition
ORDER BY column_1, column_2;

Consider the following employees table with the following data.

empno name age location salary
1 Andrew 30 India 100000
2 Beslin 29 India 90000
3 Joanna 23 USA 500000
4 Tianna 22 Canada 500000

Example for HAVING Clause

SELECT location,COUNT(empno) as count
FROM employees  
GROUP BY location
HAVING count>1;

Output

location count
India 2

Most Read