---
schema_version: "1"
id: c901805cc207f6389bfbaf7ecf70584c35419a58e1bc5cd44984932082833388
title: Use Aliases with 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-groupby-alias.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-select-groupby-alias.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 99f3fff519a291e90fdad1634994805a7e3922f0a589d9e588d64ad8ce57ccb6
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# Use Aliases with GROUP BY

You can use an alias for any field or aggregated field in a `SELECT` statement in a SOQL query. Use a field alias to identify the field when you’re processing the query results in your code.

Specify the alias directly after the associated field. For example, the following query contains two aliases: `n` for the `Name` field, and `max` for the `MAX(Amount)` aggregated field.

<!-- otherprops: set_clipboard -->

```soql
SELECT Name n, MAX(Amount) max
FROM Opportunity
GROUP BY Name
```

Any aggregated field in a `SELECT` list that does not have an alias automatically gets an implied alias with a format `expri`, where i denotes the order of the aggregated fields with no explicit aliases. The value of i starts at 0 and increments for every aggregated field with no explicit alias.

In this example, `MAX(Amount)` has an implied alias of `expr0`, and `MIN(Amount)` has an implied alias of `expr1`.

<!-- otherprops: set_clipboard -->

```soql
SELECT Name, MAX(Amount), MIN(Amount)
FROM Opportunity
GROUP BY Name
```

In this query, `MIN(Amount)` has an explicit alias of `min`, `MAX(Amount)` has an implied alias of `expr0`, and `SUM(Amount)` has an implied alias of `expr1`.

<!-- otherprops: set_clipboard -->

```soql
SELECT Name, MAX(Amount), MIN(Amount) min, SUM(Amount)
FROM Opportunity
GROUP BY Name
```
