Skip to main content

SOQL Alias Support

Essential

Standard SOQL only lets you alias the result of an aggregate function, for example SELECT COUNT(Id) total FROM Account. You cannot alias a plain field, a relationship field, or any other select expression. Brobench removes that restriction — you can add an alias to virtually every kind of item in the SELECT list, and Brobench renames the corresponding column in the results grid accordingly.

Syntax​

The general form is:

<select expression> [as] <alias>

Whether the as keyword is required, optional, or not allowed depends on the kind of select expression:

Select Expressionas keywordExample
Base fieldRequiredName as AccountName
Relationship fieldRequiredOwner.Name as OwnerName
TYPEOF ... END polymorphic fieldRequiredTYPEOF What WHEN Account THEN Phone END as WhatPhone
Function (aggregate or non-aggregate)OptionalSUM(Amount) as TotalAmount or SUM(Amount) TotalAmount

Formula Columns have their own dedicated syntax ({{expr}}:type alias) — see that page for details.

Keep in Mind
  • Aliasing is validated and applied per query level, so child (subquery) SELECT lists can use their own aliases independently of the parent query.

  • Aliasing a wildcard pattern (*, billing*, etc.) is parsed but has no effect — a single wildcard can expand into many columns, so there's no single column for the alias to rename. See Wild Card Fields for more on wildcard selection.

Examples​

SOQLDescription
SELECT Name as AccountName, Owner.Name as OwnerName FROM AccountRenames a base field and a relationship field in the results grid.
SELECT StageName, TOLABEL(StageName) as StageLabel FROM OpportunityAliases a non-aggregate function so the label column has a friendly name.
SELECT AccountId, SUM(Amount) TotalAmount FROM Opportunity GROUP BY AccountIdAliases an aggregate function without using the as keyword.
SELECT Id, (SELECT Name as ContactName FROM Contacts) FROM AccountAliases a field inside a child (subquery) relationship query.
SELECT TYPEOF What WHEN Account THEN Phone WHEN Contact THEN MobilePhone END as WhatPhone FROM TaskAliases a polymorphic TYPEOF field.