What is the function of “having” in Oracle?

In Oracle, the HAVING clause is used to filter grouped data after applying the GROUP BY clause. It is similar to the WHERE clause, but the WHERE clause is used to filter rows, while the HAVING clause is used to filter groups.

HAVING clause is typically used with the GROUP BY clause, allowing you to filter the results using aggregate functions. Only groups that meet the conditions specified in the HAVING clause will be included in the results.

Here is an example using the HAVING clause:

SELECT column1, aggregate_function(column2)
FROM table
GROUP BY column1
HAVING condition;

In the example above, the data is grouped by column1 using the GROUP BY clause, then the aggregate function is applied to column2. Finally, the HAVING clause is used to filter the results, including only the groups that meet the specified conditions.

It should be noted that the HAVING clause can only be used in group queries and not in regular queries. If the GROUP BY clause is not used, the HAVING clause cannot be used.

bannerAds