---
schema_version: "1"
id: 2fe47295f466068f114876b09f202d8372f1293c142bc693f6aa8d904e9111ee
title: Logical Operators
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-select-logicaloperators.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-select-logicaloperators.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d9e0928a8e485e6f0e216b42a053e80c1156f354f071d199a65aa7b9f5526f09
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# Logical Operators

Logical operators can be used in the field expression of the WHERE clause in a SOQL query. These operators are AND, OR, and NOT. Parentheses are required whenever you mix the operators.

The following table lists the logical operator values that are used in fieldExpression syntax:

| Operator | Syntax                                  | Description                                                                                                                   |
| -------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `AND`    | `fieldExpressionX AND fieldExpressionY` | `true` if both fieldExpressionX and fieldExpressionY are true.                                                                |
| `OR`     | `fieldExpressionX OR fieldExpressionY`  | `true` if either fieldExpressionX or fieldExpressionY is true.                                                                |
| `NOT`    | `not fieldExpressionX`                  | `true` if fieldExpressionX false. There’s also a comparison operator `NOT IN`, which is different from this logical operator. |

In a `WHERE` clause that uses `OR`, records are returned even if the foreign key value in a record is null.

```soql
SELECT Id FROM Contact WHERE LastName = 'Young' or Account.Name = 'Quarry'
```

Example `NOT` operator:

```soql
SELECT Name FROM Account WHERE AnnualRevenue > 0 AND (NOT Type = 'Prospect')
```
