If a condition refers to an aggregate function, put that condition in the HAVING clause. Otherwise, use the WHERE clause.
You can use HAVING but recommended you should use with GROUP BY.
SQL Standard says that WHERE restricts the result set before returning rows and HAVING restricts the result set after bringing all the rows. So WHERE is faster.
Tagged: Having, Performance tuning, Where
Leave a Reply