Use logical operators to perform Boolean logic between different predicates (conditions) in an SQL WHERE clause. The following outlines the logical operators supported by the SQL engine.
Operator |
Description |
|---|---|
|
Boolean OR operation |
|
Boolean AND operation |
|
Boolean NOT operation |
This allows the source table to be filtered based on multiple conditions. Logical operators compare the boolean result of two predicate comparisons, each producing a boolean result. If OR is used, either of the two predicate comparisons can result on a TRUE value for the whole expression to evaluate to TRUE. If AND is used, both predicate comparisons must evaluate to TRUE for the whole expression to be TRUE; if either is FALSE, the whole is FALSE. In the following example, if only one of the two predicate comparisons is TRUE, the line will be included in the query result set:
SELECT * FROM INHEAD WHERE ((DocumentDate > '2025-01-01') OR (PrintStatus = 'Unprinted'))
Logical operator comparisons are performed in the order of precedence: OR and then AND. To perform a comparison out of the normal order of precedence, use parentheses around the comparison to be performed first. The SELECT statement below retrieves all rows where the CountryCode field is NZ and the PriceCode is NZWSALE. It also returns those rows where the CountryCode field is AU, regardless of the value in the PriceCode field:
SELECT * FROM ARCUST WHERE ((CountryCode = 'NZ') AND (PriceCode = 'NZTRADE')) OR (CountryCode = 'AU')
Use the NOT operator to negate the boolean result of a comparison. In the following example, only those rows where the Paid field contains a FALSE value are retrieved:
SELECT * FROM INHEAD WHERE NOT (PrintStatus = 'Unprinted')