The HAVING CLAUSE is used to restrict the result set returned by the GROUP BY CLAUSE. When a programmer uses GROUP BY with the HAVING CLAUSE, the GROUP BY CLAUSE divides the rows into sets of grouped rows and aggregates their values and then the HAVING CLAUSE eliminates undesired aggregated groups.
The HAVING CLAUSE is basically used only with the GROUP BY function in a query whereas WHERE CLAUSE is applied to each row before they are part of the GROUP BY function in a query.