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
anurag singh 22anurag singh 22 

SOQL difference

Hi Guys,
I have a question could you tell me the difference in using theset wo queries?

Query1
list<account>account list=[select id,name from account where id=:(set<Id>AccountId's)];
Query2:
list<account>account list=[select id,name from account where id IN:(set<Id>AccountId's)];

Is there an advantage of using one over the other as a best practice?If so which is better to use because frankly the only difference I can see is the second one checks for contains apart from that I do not see any difference

 

Nitin PaliwalNitin Paliwal
Hi anurag,
The difference is that equals operator cannot be used while performing Join in the SOQL, whereas IN operator can be used.
Exampler:
list<Account> acc = [select Id from Account where Id =  (Select AccountId from Contact)]; --- NOT ALLOWED
list<Account> acc = [select Id from Account where Id IN (Select AccountId from Contact)]; -- ALLOWED

I hope this solves your queries.


Thanks
Nitin