---
schema_version: "1"
id: 7c7696c1a2802bc86c8a46b6a4a0dd83460d4097b6f3006ffba01b82da7e056e
title: Considerations for GROUP BY
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-select-group-by-considerations.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-select-group-by-considerations.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b03e1ea16bf592cce72f299d0903e1dcbaa17bd39fa87276f207cc75d69a66da
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# Considerations for GROUP BY

Understand the special behavior and limitations for using the `GROUP BY` clause in SOQL queries.

- Some object fields have a field type that doesn’t support grouping. You can't include fields with these field types in a `GROUP BY` clause.

  To check whether a field supports grouping, you can use SOAP API or REST API to make a describe call for the object that contains the field. For each field, the response includes a boolean `groupable` attribute that defines whether you can include the field in a `GROUP BY` clause. To check whether a field supports grouping for standard objects, you can also check the properties for the field in the _Object Reference for Salesforce and Lightning Platform_.

- You must use a `GROUP BY` clause if your query has a `LIMIT` clause and an aggregated function. For example, the following query is valid:

  <!-- otherprops: set_clipboard -->

  ```soql
  SELECT Name, Max(CreatedDate)
  FROM Account
  GROUP BY Name
  LIMIT 5
  ```

  The following query is invalid as there’s no `GROUP BY` clause:

  <!-- otherprops: set_clipboard -->

  ```soql
  SELECT MAX(CreatedDate)
  FROM Account LIMIT 1
  ```

- You can't use child relationship expressions that use the `__r` syntax in a query that uses a `GROUP BY` clause. For more information, see [Understanding Relationship Names, Custom Objects, and Custom Fields](https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-relationships-and-custom-objects.md#understanding-relationship-names-custom-objects-and-custom-fields).
- In SOAP API, queries that include a GROUP BY clause can't use the [queryMore()](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_querymore.htm) call to get more results.
- In REST API, queries that include a GROUP BY clause can’t use the [query locator](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query_more_results.htm) to get more results.
- Formula fields can't be grouped.
