Alias notation in SOQL is used to give a short name to an object or relationship inside a SOQL SELECT statement. After the alias is declared, you can use that alias in the remaining parts of the query instead of repeating the full object or relationship name.
This is useful when a query refers to more than one object path, especially when you filter records through a parent relationship. SOQL alias notation is not the same as SQL column aliasing, so this tutorial explains both object aliases and the limited field aliases used with GROUP BY queries.
SOQL alias notation syntax for an object name
To create an object alias, first write the object name in the FROM clause and then write the alias name after it. SOQL does not use the AS keyword for this object alias syntax.
SELECT AliasName.FieldName
FROM ObjectName AliasName
WHERE AliasName.FieldName = 'value'
For example, if Account is given the alias Acct, then Acct.Id means the Id field of the Account record and Acct.Name means the Name field of the same Account record.
SOQL reserved keywords that should not be used as alias names
In Salesforce SOQL, reserved query keywords should not be used as alias names because they already have a fixed meaning in the query language. Common reserved words include:
- AND
- ASC
- DESC
- EXCLUDES
- FIRST
- FROM
- GROUP
- HAVING
- IN
- INCLUDES
- LAST
- LIKE
- LIMIT
- NOT
- NULL
- NULLS
- OR
- SELECT
- WHERE
- WITH
Use clear short aliases such as Acct, Con, Opp, or OwnerUser. Avoid aliases that look like field names or SOQL clause names, because they make the query harder to read and easier to misinterpret.
Before using aliases in Apex or the Developer Console, remember that alias names only improve how the query refers to objects, relationships, and grouped result values. They do not change the underlying Salesforce field API names.
Filtering still uses the normal WHERE clause and comparison operators in the SOQL query; the alias simply gives you a shorter reference for the object or relationship path.
Example – Alias Notation in SOQL
Following is an example SOQL query, the object is Account and it’s alias name is Acct.
SELECT Acct.Id, Acct.name FROM Account Acct
From the above code, Acct is the alias name for the Account object. The query fetches the Account Id and Name fields by qualifying them with the alias. The same data can also be fetched without alias notation, but the alias becomes helpful when the query contains a relationship path or when you want a shorter object reference.
Output
Using SOQL alias notation with Contact and Account relationship fields
In Salesforce.com, using SOQL statement we can fetch data using Alias notation from different objects. Let us understand with an example.
SELECT FirstName, LastName FROM Contact Con, Con.Account Acct WHERE Acct.Name = 'Genepoint'
As shown above, Con is the alias name for Contact and Acct is the alias name for Account object.

Here we fetch FirstName and LastName from the Contact object and filter those contacts by the related Account name. Because contacts are associated with accounts through the Account relationship, the alias Acct can be used in the WHERE clause to refer to the parent account path.

Object aliases in SOQL are different from SQL column aliases
A common mistake is to treat SOQL exactly like SQL and try to rename a normal selected field with AS. For ordinary object queries, keep the original field API names in the SELECT list. The following SQL-style pattern is not the right way to rename a normal SOQL field.
SELECT Name AS AccountName
FROM Account
For a normal Account query, write the field name directly:
SELECT Id, Name
FROM Account
If you need a different key name in Apex, JavaScript, middleware, or an integration response, rename the value after reading the SOQL result rather than trying to rename a regular field in the SELECT clause.
SOQL field aliases with GROUP BY and aggregate results
SOQL also supports field aliases in grouped aggregate queries. In this case, the alias is written immediately after the selected field or aggregate expression. Do not use AS.
SELECT Name accountName, MAX(Amount) maxAmount
FROM Opportunity
GROUP BY Name
When an aggregate expression has no explicit alias, Salesforce returns an implied alias such as expr0, expr1, and so on. Giving the aggregate expression a readable alias can make Apex code easier to understand.
SELECT AccountId, COUNT(Id) totalContacts
FROM Contact
GROUP BY AccountId
HAVING COUNT(Id) > 0
ORDER BY totalContacts DESC
In the above query, totalContacts is an alias for the COUNT(Id) aggregate value. This type of alias is meant for grouped query results, not for renaming every normal field in every SOQL query.
Reading a SOQL aggregate alias in Apex
When a SOQL query returns aggregate data, the result type is AggregateResult. Use the alias name with get() to read the value.
List<AggregateResult> rows = [
SELECT AccountId accountId, COUNT(Id) totalContacts
FROM Contact
GROUP BY AccountId
];
for (AggregateResult row : rows) {
Id accountId = (Id) row.get('accountId');
Integer totalContacts = (Integer) row.get('totalContacts');
System.debug(accountId + ' has ' + totalContacts + ' contacts');
}
If you omit the alias on COUNT(Id), then the aggregate value must be read using the implied name such as expr0. For readable production code, explicit aggregate aliases are usually easier to maintain.
Common SOQL alias notation mistakes and fixes
| Mistake | Why it causes confusion | Better approach |
|---|---|---|
| Using a reserved keyword as an alias | SOQL reads words like WHERE, GROUP, and LIMIT as query clauses. | Use a short descriptive alias such as Acct or Con. |
Using AS for object aliases | SOQL object alias notation is written directly after the object name. | Write FROM Account Acct. |
| Trying to rename normal fields in a simple SELECT query | Regular sObject fields are returned using their API names. | Rename values after the query in Apex or in the API client. |
Forgetting that aggregate aliases are read from AggregateResult | Aggregate queries do not return normal sObject records. | Use row.get('aliasName') to read the value. |
Official Salesforce references for SOQL alias notation
For deeper reference, see Salesforce documentation on SOQL alias notation and using aliases with GROUP BY.
FAQs on Alias Notation in SOQL
What is alias notation in SOQL?
Alias notation in SOQL gives a short name to an object or relationship in a SELECT query. After the alias is declared, it can be used in the rest of the query to refer to that object or relationship path.
Can I use AS for SOQL object aliases?
No. For object aliases, SOQL uses the object name followed directly by the alias, such as FROM Account Acct. The SQL-style AS keyword is not used for object alias notation.
Can I rename a normal field such as Name in a SOQL query?
For a simple non-aggregate query, selected fields are returned using their field API names. If you need a different display name, rename the value after retrieving the result.
When should I use aggregate aliases like totalContacts in SOQL?
Use aggregate aliases in GROUP BY queries when you want a readable name for an aggregate value such as COUNT(Id), SUM(Amount), or MAX(CreatedDate). The alias can then be read from AggregateResult.
SOQL alias notation editorial QA checklist
- Confirm every SOQL alias is declared after the correct object or relationship path.
- Check that no alias uses a SOQL reserved keyword such as
SELECT,WHERE, orGROUP. - Do not add
ASto SOQL object alias examples. - For aggregate examples, verify that aliases are read from
AggregateResultusing the same alias name. - Keep relationship examples clear about which object is the base object and which object is reached through a parent relationship.
Conclusion: choosing the right SOQL alias notation
In this Salesforce Developer Tutorial, we learned that SOQL alias notation is mainly used for object and relationship references, while GROUP BY queries can also use readable field or aggregate aliases. For more filtering examples, continue with SOQL IN operator.
TutorialKart.com