GROUP BY, ORDER BY and LIMIT in SOQL

GROUP BY, ORDER BY and LIMIT in SOQL

Example:

SELECT Name,MAX(NumberofLocations__c) FROM Account GROUP BY name ORDER BY Name LIMIT 2

Field that are aggregated cannot be used in GROUP BY or ORDER BY.

In the above example, NumberOfLocations__c cannot be used in GROUP BY or ORDER BY because NumberOfLocations__c is aggregated.

Leave a Reply