Using the HAVING clause
HAVING clause is very similar to the
WHERE clause. However, the only difference between the
WHERE clause is that the
HAVING clause is used only with the aggregate functions.
HAVING clause is used to specify the search condition in the
GROUP BY clause or the aggregate functions. The
HAVING clause limits the grouped records returned by a SOQL statement. However, the
WHERE clause limits the records returned by a SOQL statement.
HAVING clause in SOQL is used to specify that the SOQL
SELECT statement should only return the records whose aggregate values meet the specified conditions.
A sample query is given as follows:
SELECT City__c, COUNT(Employee_Name__c) FROM Employee__c GROUP BY City__c HAVING COUNT(City__c) ...