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
Prangya JenaPrangya Jena 

Alias for field name in SOQL

Hi All,

Do we have alias for Field names in SOQL as we have in SQL. 
I know we have alias for aggregate functions , but i have a need where i want alias for field names as two of my field API names are same.

Thanks in advance
Jyoti Sahoo 3Jyoti Sahoo 3
Hi Prangya,

Alias Notation

You can use alias notation in SELECT queries: SELECT count() FROM Contact c, c.Account a WHERE a.name = 'MyriadPubs'
To establish the alias, first identify the object, in this example a contact, and then specify the alias, in this case “c.” For the rest of the SELECT statement, you can use the alias in place of the object or field name.
The following are SOQL keywords that can’t be used as alias names: AND, ASC, DESC, EXCLUDES, FIRST, FROM, GROUP, HAVING, IN, INCLUDES, LAST, LIKE, LIMIT, NOT, NULL, NULLS, OR, SELECT, WHERE, WITH
 
Prangya JenaPrangya Jena
Hi Jyoti,

Thank you. But as my question suggests i want alias for field names of those objects. 
ex- I have ''Name'' field in Contact and Account object . So while querying ''Name'' i want one of my Name field should come as alias.
Let me know if you have understood what my question is.