Is there any advantage of using operator "IN" instead of "NOT IN" in SOQL? Are there any performance benefits of it?

I have a use case where I have to filter the records based on a certain column, say Region, which has many distinct values. NOT IN is preferable since only a fraction of those distinct values will be used for filteration.

e.g. let there be 10 distinct values in Region ... 1. NJ 2. NY 3. .. ..... 10. CL

the NOT IN will only contain, say NJ and NY


2 Answers 2


I believe using selective query like IN is preferable over NOT IN.

When your filter uses != or NOT—which includes using NOT EQUALS/CONTAINS for reports, even if the field is indexed—the Force.com query optimizer can’t use the index to drive the query. For better performance, filter using = or IN, and the reciprocal values.



When you have IN in your where clause, the query restricts the records then writing NOT IN.

In the above scenario, it will not make much any unless you are trying to fetch all the records based on Region not having NJ and NY

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .