Alias Notations in SOQL : In our previous salesforce tutorial we have learned about how to write our first SOQL statement. In this salesforce training tutorial we are going to learn about Basic SOQL statement called Alias notation.
What is the alias notation in SOQL ?
Alias notation in SOQL statements are used to distinguish different object used in a single SOQL Statement.They are different types SOQL reserved keywords that can not be used in alias names or alias notations in SOQL. Some of the alias name are.
Let us see an example to understand alias notations in SOQL.
- SELECT Acct.Id, Acct.name FROM Account Acct
From above SOQL statement we fetching Account Id, Account name records from the Standard object called Account. we have mentioned the word “ Acct”. “Acct” is the alias name for “Account”. We can fetch data directly with out using alis name in order to understand alias names in SOQL we are using alias names in this example.
- SELECT Firstname, lastname FROM Contact Con, Con.Account Acct WHERE Acct.name= ‘Ashok‘
From above SOQL Statement Acct is the alias name for “Account” Con is the alias name for “Contact”. We are fetching firstname and lastname from two objects called Contacts and Account. In both contacts and account we have firstname and lastname. Where is the condition to get the details from specific record called “Ashok”.
From above SOQL statement we fetching lastname and firstname from the Account and Contacts of Ashok. These alias name are helpful when writing SOQL queries for multiple objects. When writing SOQL statements for multiple objects many fields are common in all the objects so the alias names are helpful to distinguish the difference between the objects.