What is the between WHERE and HAVING clause in SQL and MySQL?

Sarthak Niwate
1 min readDec 5, 2020

Adding a WHERE clause to a query allows you to set a condition which you can use to specify what part of the data you want to retrieve from the database.

HAVING is a clause frequently implemented with GROUP BY because it refines the output from records that do not satisfy a certain condition.
HAVING needs to be inserted between the GROUP BY and ORDER BY clauses. In a way, HAVING is like WHERE but applied to the GROUP BY block.

On some occasions, an identical result could be obtained by implementing the same condition, either with the WHERE or with the HAVING clause.

The main distinction between the two clauses is that HAVING can be applied for subsets of aggregated groups, while in the WHERE block, this is forbidden. In other words, after HAVING, you can have a condition with an aggregate function, while WHERE cannot use aggregate functions within its conditions.

Resourse: 365 Data Science

--

--