Evaluation Order of WHERE, GROUP BY, and HAVING Clauses
When the WHERE, GROUP BY, and HAVING clauses are used together in a SELECT statement, the order of evaluation is as follows:
1 WHERE
2 GROUP BY
3 HAVING
Tables referenced in a HAVING clause must be specified in one of the following:
You can use the HAVING clause when referencing columns from two or more tables.