Newer Version Available

This content describes an older version of this product. View Latest

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.

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.

In a WHERE clause that uses OR, records are returned even if the foreign key value in a record is null.

1SELECT Id FROM Contact WHERE LastName = 'Young' or Account.Name = 'Quarry'
NOT not fieldExpressionX true if fieldExpressionX is false.

There is also a comparison operator NOT IN, which is different from this logical operator.