---
schema_version: "1"
id: 6b1c09c974ed69ed2bdb7222be08015d9b2ae0bc4822f39f7ee6b68c919462bd
title: "ApexGuru Antipattern: SOQL with Negative Expressions"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/apexguru_antipattern_soql_with_negative_expressions.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.apexguru_antipattern_soql_with_negative_expressions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 00496290c9e2eb00c79af400d5be6d5a71a73dd5adac72f2c2a332e8e9dfcf6f
description: SOQL queries that use negative expressions such as NOT IN or != don't index effectively, leading to full-table scans. Less-efficient database operations increase query time and CPU usage. Avoid negative expressions. Use positive expressions wherever possible.
products:
  - Cross Cloud
release: "264"
---
# ApexGuru Antipattern: SOQL with Negative Expressions

SOQL queries that use negative expressions such as NOT IN or != don't index effectively, leading to full-table scans. Less-efficient database operations increase query time and CPU usage. Avoid negative expressions. Use positive expressions wherever possible.

## Scope

Detection only

## Detection Example

```java
apex
  [SELECT Id FROM Opportunity WHERE StageName NOT IN ('Closed Won', 'Closed Lost')];
```