Professional Documents
Culture Documents
Soql 1670482386
Soql 1670482386
When we want to add multiple conditions in SOQL AND & OR keywords are used.
Eg.
[SELECT Id, Name, Phone FROM Account WHERE Rating=’Hot’ AND
Industry=’Transportation’]
[SELECT Id, Name, Phone FROM Account WHERE Rating=’Hot’ OR
Industry=’Transportation’]
Now if we want to give multiple conditions to the same field then we need to use
OR Keyword many times.
Eg.
[SELECT Id, Name, Phone FROM Account WHERE Industry=’Transportation’ OR
Industry=’Consulting’ OR Industry=’Energy’]
LIMIT keyword
When we want to retrieve first any number of records use the LIMIT keyword.
Eg.
[ SELECT Id, Name, Phone FROM Account WHERE Rating=’Hot’ LIMIT 3]
Relationship Queries
When we want to write a Query with more than one object but there should
share relation in between that object.
Parent and child relationship
When we want to query a child record from a parent object in this case the main
object will be the parent object.
Eg.
[SELECT Id, Name, Phone, Industry, (SELECT Name, Phone FROM Contacts) FROM
Account]
When we are writing parent to child query for custom objects then child custom
object name should be written with suffix __r ( underscore underscore r)
Eg.
[SELECT Name, Phone__c, (SELECT Name__c, Book__c, FROM Students__r) FROM
School__c]
Thankyou