Using disjunctions in complex queries
ServiceNow performs conjunction (AND) statements before disjunction (OR) statements in a query.
When you create a complex query that combines AND and OR conditions, you must use parenthesis around disjunctions to ensure proper grouping of query elements.
Example
Find all closed incidents (state = 6) that are either Priority 1 or Priority 2.
-
Correct query (with parentheses):
Text(priority = 1 || priority = 2) && state = 6This query returns all closed incidents where the priority is 1 OR 2.
-
Incorrect query (without parentheses):
Textpriority = 1 || priority = 2 && state = 6Without parentheses, this query is evaluated as: priority = 1 OR (priority = 2 AND state = 6). This returns ALL Priority 1 incidents regardless of state, plus only the closed Priority 2 incidents.
|
Query |
Evaluated as |
Result |
|---|---|---|
|
Text |
(P1 OR P2) AND Closed |
Closed P1 and P2 incidents only |
|
Text |
P1 OR (P2 AND Closed) |
ALL P1 incidents + only closed P2 |
Parent Topic:Working with database views for reporting
Related topics
Joining tables using database views
---
title: Using disjunctions in complex queries
description: ServiceNow performs conjunction \(AND\) statements before disjunction \(OR\) statements in a query.
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/australia/platform-administration/table-administration-and-data-management/c\_UseDisjunctionsInComplexQueries.html
release: australia
product: Table Administration and Data Management
classification: table-administration-and-data-management
topic_type: concept
last_updated: "2026-09-10"
reading_time_minutes: 1
breadcrumb: [Work with database views, Table admin, Tables and data, Configure core features, Administer the ServiceNow AI Platform]
---
# Using disjunctions in complex queries
ServiceNow performs conjunction \(AND\) statements before disjunction \(OR\) statements in a query.
When you create a complex query that combines AND and OR conditions, you must use parenthesis around disjunctions to ensure proper grouping of query elements.
## Example
Find all closed incidents \(state = 6\) that are either Priority 1 or Priority 2.
- Correct query \(with parentheses\):
```
(priority = 1 || priority = 2) && state = 6
```
This query returns all closed incidents where the priority is 1 OR 2.
- Incorrect query \(without parentheses\):
```
priority = 1 || priority = 2 && state = 6
```
Without parentheses, this query is evaluated as: priority = 1 OR \(priority = 2 AND state = 6\). This returns ALL Priority 1 incidents regardless of state, plus only the closed Priority 2 incidents.
<table id="table_kfj_vgn_yhc"><thead><tr><th>
Query
</th><th>
Evaluated as
</th><th>
Result
</th></tr></thead><tbody><tr><td>
```
(priority = 1 || priority = 2) && state = 6
```
</td><td>
\(P1 OR P2\) AND Closed
</td><td>
Closed P1 and P2 incidents only
</td></tr><tr><td>
```
priority = 1 || priority = 2 && state = 6
```
</td><td>
P1 OR \(P2 AND Closed\)
</td><td>
ALL P1 incidents + only closed P2
</td></tr></tbody>
</table>Always use parentheses around OR conditions when combining them with AND conditions. This ensures your query returns the expected results.
**Parent Topic:**[Working with database views for reporting](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/table-administration-and-data-management/c_DatabaseViews.md)
**Related topics**
[Joining tables using database views]()
[Displaying function results in a database view]()
[Database views in the base system]()
| title | Using disjunctions in complex queries |
| description | ServiceNow performs conjunction \(AND\) statements before disjunction \(OR\) statements in a query. |
| locale | en-US |
| canonical_url | https://www.servicenow.com/docs/r/australia/platform-administration/table-administration-and-data-management/c\_UseDisjunctionsInComplexQueries.html |
| release | australia |
| product | Table Administration and Data Management |
| classification | table-administration-and-data-management |
| topic_type | concept |
| last_updated | 2026-09-10 |
| reading_time_minutes | 1 |
| breadcrumb | Work with database viewsTable adminTables and dataConfigure core featuresAdminister the ServiceNow AI Platform |