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.

  1. AND.
  2. ASC
  3. DESC.
  4. EXCLUDES.
  5. FIRST.
  6. FROM.
  7. GROUP.
  8. HAVING.
  9. IN.
  10. INCLUDES.
  11. LAST.
  12. LIKE.
  13. LIMIT.
  14. NOT.
  15. NULL.
  16. NULLS.
  17. OR.
  18. SELECT.
  19. WHERE.
  20. WITH

Let us see an example to understand alias notations in SOQL.

  • SELECT Acct.Id, Acct.name FROM Account Acct
Alias Notations in SOQL|Basic SOQL Statements

Alias Notations in SOQL|Basic SOQL Statements

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
Alias Notations in SOQL|Basic SOQL Statements

Alias Notations in SOQL|Basic SOQL Statements

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.