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
Nandika Kodituwakku 10Nandika Kodituwakku 10 

how to Alias a column in SOQL

Hi Devs,

How do we something simple like below in SOQL.

SELECT ID as  ROW_NATURAL_ID FROM ACCOUNT;

Regards,
Nandika
Vikas gupta 24Vikas gupta 24
Hi Nandika,

you can't create alisa on field, in salesforce it is allow only with the aggregate function. like below
 
select count(id) Total from opportunity

In above it will create default alias expr0 to total. 

Thanks, Vikas
VineetKumarVineetKumar
SOQL has very limited aliasing support. You can alias the table, e.g. SELECT a.name FROM Account a, but that's of very little use. In most contexts you cannot alias fields.
The one exception is for queries that use aggregations, like SELECT COUNT(Id) recordCount FROM Account allows you to alias the result of the aggregation from it's default expr0 to recordCount.
Sunil Shah 12Sunil Shah 12
Thanks Vineet :)
Jeremy West 15Jeremy West 15
Wow... that is irritating. 

So we have to change all our code downstream whenever we make a change to underlying data structure?

 
Roman BieleiRoman Bielei
Finally we have found decision how to "rename" column in SOQL without using standart Aggregate function that requires Group by clause in the end, and unfortunately doesn`t allow to export more that 2000 rows in query.
The best way is using Format(Field) Custom_Name. It could be tricky way to use this with some dates values or e.t.c cause function changes format of values in field.
Morton HsiaoMorton Hsiao
Wow 5 years later and still no solution. What happens when you've got something like field__r.name__c, field__r.address__c wiht a soql and simple salesforce and one comes back as field__r, and the other one comes back blank
Boris Todorov GichevBoris Todorov Gichev

Hi SF people, 

came acorss this topoic. I think SF is not implementing this on purpose, so that you know what you get from the query. And to try to tell you that when sending data to the FE it is always a good idea to use a wrapper obejct and there you can name things as you wish. So think of this as a way to keep integrity and push you to the good developing practices. 

odde shankargangaodde shankarganga
How do I give a column alias in SOQL?
Alias notation in SOQL statements are used to distinguish different object used in a single SOQL Statement. To establish the alias, first we should identify the object and then specify the alias. In Salesforce SOQL, we have some reserved keywords which are not used as alias names.
Li LauraLi Laura
Thank you so much for sharing this info which really helpful to solve my issue...
Retrol Bowl (https://retrobowl-game.com/)
Jaun MarkJaun Mark
Great advice for the suggestion! SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. If you would be interested in more about it you can check it. (https://mmcgbl.com/software-quality-assurance/)
Landry OtooleLandry Otoole
How do I turn off notifications? They keep popping out during gaming and it is extremely annoying.
http://narwhaleio.us
Praveen ChoudharyPraveen Choudhary
Great advice for the suggestion! SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. If you would be interested in more about it you can check it. Asktop10 (https://asktop10.com/)
nokev veriynokev veriy
Thanks for sharing. If you glance at your smartphone or digital timer and notice 1111. You can tell that your Angels want to gain your attention. Visit here: 1111 Angel Number
Landry OtooleLandry Otoole

Pointing your fingers is a very rude thing to do, especially when you don’t know a person.

https://snakeio.info

Landry OtooleLandry Otoole

Evolution is funny thing actually, sometimes it makes hilarious mistakes and we have weird species of animals.

https://mahjongtitans.us

Lawal IdrisLawal Idris
Thanks for sharing. Check out this site angel number