---
schema_version: "1"
id: fc4cd1cbc97cc9e594c304f400faed56f17ca2eef4c39ee142dff818b23d63f5
title: Boolean Operators
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/graphql-api/graphql/guides/filter/filter-boolean.md
canonical_url: https://developer.salesforce.com/docs/platform/graphql/guide/filter-boolean.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 61cf7dad0aab2de23dcf816b726cd8d2a94a912be3a15bd074838cff5a0f2f13
products:
  - GraphQL API
---
# Boolean Operators

| AVAILABLE API VERSION |
| --------------------- |
| API v56.0 and later   |

To filter the result set, a query combines several predicates. Boolean operators can help you expand or narrow your query within the `where` filter. Use the `OR` function to combine filters. Use the `AND` function to intersect filters. The `NOT` function inverts a filter.

The filter types have fields for the `AND`, `OR`, and `NOT` functions. `AND` and `OR` take in a list, while `NOT` takes in a single filter to invert. When combined, the filters allow for arbitrary boolean expressions.

```
input Account_Filter {
  and: [Account_Filter]
  or:  [Account_Filter]
  not: Account_Filter
}
```

Each filter within the list of filters is joined by the named operator for `AND` or `OR` functions.

## AND Expressions

Let’s look at a list of filters with the `and` operator.

```
where: {
  and: [ {filter1}, {filter2} ]
}
```

Each filter is joined with the `AND` SOQL operator.

```
WHERE (filter1) AND (filter2)
```

Here's an example of the previous list of filters.

```
where: {
  and: [{
    AnnualRevenue: {
      gt: 100000
    }
},
  {
    AnnualRevenue: {
      lt: 1000000
    }
  }]
}
```

Similarly, consider the following filters.

```
where: {
  and: [filter1, filter2, filter3]
}
```

The implicit filter with the `and` operator is similar to a SOQL statement that looks like this.

```
WHERE (filter1 AND filter2 AND filter3)
```

Whenever two operators have a value on the filter type, the query combines them with an implicit AND operator.

```
Opportunity(
  where: {
    NextStep: {eq: "Need estimate"}
    CloseDate: {
      CALENDAR_MONTH: {
        value: {
          eq: 10
        }
      }
    }
  }
)
```

This query is similar to the following SOQL statement. It assumes that `Id` and `Name` are included in a `SELECT` clause.

```
FROM Opportunity
WHERE NextStep='Need estimate' AND CALENDAR_MONTH(CloseDate)=10
```

Similarly, the following query contains multiple operators `eq` and `gt` with a value on the filter type.

```
Account(
  where: {
    AnnualRevenue: {gt: 1000000}
    Ownership: {eq: "Public" }
    ShippingCity: {
      eq: "Tokyo"
    }
  }
)
```

The previous query is similar to the following SOQL statement. It assumes that `Id` and `Name` are included in a `SELECT` clause.

```
SELECT Id, Name
FROM Account
WHERE AnnualRevenue>1000000 AND Ownership='Public' AND ShippingCity='Tokyo'
```

## OR Expressions

Similarly, a filter with the `or` operator looks like this.

```
where: {
  or: [filter1, filter2, filter3]
}
```

The `OR` function is similar to the following SOQL statement.

```
WHERE (filter1 OR filter2 OR filter3)
```

Let’s look at how to use the `or` filter type.

```
Account(
  where: {
    or: [
        { AnnualRevenue: {gt: 10000000} }
        { Ownership: {eq: "Public"} }
    ]
  }
)
```

The previous query is similar to this SOQL statement with the `OR` operator. It assumes that `Id` and `Name` are included in a `SELECT` clause.

```
SELECT Id, Name
FROM Account
WHERE AnnualRevenue>10000000 OR Ownership='Public'
```

## NOT Expressions

The `NOT` function inverts the predicate within the filter.

```
Account(
  where: {
    not: {
      ShippingCity: {
        eq: { "Tokyo" }
      }
    }
  }
)
```

The previous query is similar to the following SOQL statement with the `NOT` operator. It assumes that `Id` and `Name` are included in a `SELECT` clause.

```
SELECT Id, Name
FROM Account
WHERE NOT ShippingCity='Tokyo'
```

The `NOT` function can be used with the binary functions as well.

```
where: {
  not: {
    and: [filter1, filter2]
  }
}
```

The previous `NOT` function is similar to the following SOQL statement.

```
WHERE NOT (filter1 AND filter2)
```

This query uses the `not` filter type with multiple `and` filters.

```
Opportunity(
  where: {
    not: { Probability: { eq: 100 }
           StageName: { eq: "Closed Won" }
    }
  }
)
```

The previous query is similar to the following SOQL statement with the `WHERE NOT` clause.

```
SELECT Id, Name
FROM Opportunity
WHERE NOT (Probability=100 AND StageName='Closed Won')
```

## Filter Nesting

Furthermore, we can have arbitrary nesting of filters.

```
where: {
  and: [
    {or: [filter11, filter12]},
    {or: [filter21, filter22]}
  ]
}
```

The nesting of filter is similar as follows.

```
WHERE ( (filter11 OR filter12) AND (filter21 OR filter22) )
```

This query uses nesting of filters.

```
Opportunity(
    where: {
      or: [
        {
          Probability: { eq: 100 },
          StageName: { eq: "Closed Won" }
        },
        {
          Type: { eq: "New Customer" },
          ExpectedRevenue: { gt: 1000000 }
        }
      ]
    }
)
```

The previous query is similar to the following SOQL statement.

```
SELECT Id, Name
FROM Opportunity
WHERE (Probability=100 AND StageName='Closed Won') OR (Type='New Customer' AND ExpectedRevenue>1000000)
```
