Newer Version Available

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

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:

1fieldExpression [logicalOperator fieldExpression2][...]

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'
  • SELECT Name FROM Account WHERE CreatedDate > 2011-04-26T10:00:00-08:00

    You can use date or datetime values, or date literals. The format for date and dateTime fields are different.

  • 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:
    1fieldExpression1 AND (fieldExpression2 OR fieldExpression3)
  • However, the following expression is true if either fieldExpression3 is true or both fieldExpression1 and fieldExpression2 are true.
    1(fieldExpression1 AND fieldExpression2) OR fieldExpression3
  • Client applications must specify parentheses when nesting operators. However, multiple operators of the same type do not need to be nested.

The WHERE clause behaves in two different ways, depending on the version, when handling null values in a parent field for a relationship query. In a WHERE clause that checks for a value in a parent field, if the parent does not exist, the record is returned in version 13.0 and later but is not returned in versions before 13.0

1SELECT Id
2FROM Case
3WHERE Contact.LastName = null

Note