Newer Version Available
WHERE
The condition expression in a WHERE clause of a SOQL query includes one or more field expressions. You can specify multiple field expressions in a
condition expression by using logical operators.
Syntax
1WHERE conditionExpressionconditionExpression
The conditionExpression uses the following syntax:
1fieldExpression [logicalOperator fieldExpression2][...]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 information on date functions, such as CALENDAR_YEAR(), see Date Functions.
You can use the boolean values TRUE and FALSE in SOQL queries. To filter on a boolean field, use the following syntax:
1WHERE BooleanField = TRUE
2
3WHERE BooleanField = FALSEfieldExpression
The field expression syntax of the WHERE clause in a SOQL query consists of a field name, a comparison operator, and a value. The query uses these components to compare the field name value to records being searched.
1fieldName comparisonOperator value
You can use parentheses to define the order in which
fieldExpressions are evaluated. You must specify parentheses
when nesting operators. However, multiple operators of the same type don’t need to
be nested. In the following example, the 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.
1fieldExpression1 AND (fieldExpression2 OR fieldExpression3)1(fieldExpression1 AND fieldExpression2) OR fieldExpression3