The MySQL HAVING Clause is used with GROUP BY clause, because aggregate functions could not be used with WHERE keyword. It always returns the rows where condition is TRUE. The HAVING clause is often used with the GROUP BY clause to filter groups based on a specified condition.
To filter groups based on a specified condition, use the following syntax:
Parameters:
tablename: The table name from which you want to fetch the records.
condition: To specify the conditions that must be fulfilled for the records to be selected.
HAVING: To sort data set in ascending order.
ORDER BY: To specify filter conditions for a group of rows or aggregates. It shows only those groups in result set whose conditions are TRUE.
Note:
In the above example, we have fetched records using filter groups based on a specified condition using HAVING
.
You can use MySQL Command Line Client to fetched records using filter groups based on a specified condition using HAVING
. It will look like this: