function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Not able to find how to Alias Columns in a SOQL query

Its bad but its a limitation of SOQL I cant use


Select Id, First_Name__c As 'Name from Candidate


This is really very bad




By "AS" , do you mean you want to query for names which are like the string you are searching for?

Chamil MadusankaChamil Madusanka

There are no field alias's in SOQL, only object aliases.


If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.


Best I know you use Alias if you grouo by

select id, Name n from Account group by Id, Name..


Does anyone know without using group by ?


I'm looking for a way to do this as well...
I'm working with a child object subquery and need a good way to access the list of children from my query results


You access the child records by using the relationship name. The relationship between the Account and Contact objects is named 'Contacts'.


list<Account> accs = [SELECT Name, (SELECT FirstName, LastName FROM Contacts) FROM Account];
for(Account acc : accs)
    for(Contact con : acc.Contacts)
        system.Debug('Contact:' + con.LastName);


Awesome! I couldn't find examples of this ANYWHERE



     "Alias" only work with aggregate functions. if you use alias in normal SOQL query you will get error like this,


     MalformedQueryFault :

                    <ns1:exceptionCode>MALFORMED_QUERY</ns1:exceptionCode><ns1:exceptionMessage>only aggregate expressions use field aliasing</ns1:exceptionMessage><ns1:row>-1</ns1:row><ns1:column>-1</ns1:column>