Newer Version Available

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

Condition Expression Syntax (WHERE Clause)

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 MailingCity='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:
  • 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.
  • Only the first 254 characters in a rich text area or long text area field are considered in fieldExpressions.

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 not returned in versions before 13.0.

Case record Id values are returned in version 13.0 and later, but are not returned in versions before 13.0.

Note