- WHERE clause will apply some restrict condition for each row in the table
- GROUP BY clause will create groups only from the rows satisfying the where condition
- HAVING clause will apply restrict condition on the groups produced by GROUP BY clause.
Having clause is used to restrict group-level rows. It can not be used without GROUP BY clause to be used.
Example:
We can use WHERE and HAVING clause in the same statement in case we want to do double restriction with the following logic:
For example:
It is important to remember that HAVING clause must contain a group function or expression that uses such, otherwise we will get an error, for example:
No comments:
Post a Comment