The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns.
Syntax:
SELECT column(n) FROM table_name
WHERE [ conditions ]
GROUP BY column(n) HAVING conditions ORDER BY column(n)
When WHERE, GROUP BY and HAVING clauses are used together in a SELECT statement, the WHERE clause is processed first, then the rows that are returned after the WHERE clause is executed are grouped based on the GROUP BY clause.