Newer Version Available
Condition Expression Syntax (WHERE Clause)
The syntax of the condition expression in a WHERE
clause of a SOQL query includes one or more field expressions. You can specify multiple field
expressions to a condition expression by using logical operators.
The conditionExpression in the WHERE clause in a SOQL statement uses the following syntax:
You can add multiple field expressions to a condition expression by using logical operators.
The condition expressions in SOQL SELECT statements appear in bold in these examples:
- SELECT Name FROM Account WHERE Name LIKE 'A%'
- SELECT Id FROM Contact WHERE Name LIKE 'A%' AND MailingState='California'
You can use date or datetime values, or date literals. The format for date and dateTime fields are different.
- SELECT Name FROM Account WHERE CreatedDate > 2011-04-26T10:00:00-08:00
- SELECT Amount FROM Opportunity WHERE CALENDAR_YEAR(CreatedDate) = 2011
For more information on date functions, such as CALENDAR_YEAR(), see Date Functions.
You can use parentheses to define the order in which
fieldExpressions are evaluated. For example, the following expression is
true if fieldExpression1
is true and either fieldExpression2 or fieldExpression3 are true:
However,
the following expression is true if either fieldExpression3 is true or both
fieldExpression1 and fieldExpression2 are true.
Client
applications must specify parentheses when nesting operators. However, multiple operators of the
same type do not need to be nested.