Newer Version Available

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

WITH filteringExpression

The WITH clause is used in a SELECT statement to filter records based on field values. Unlike the WHERE clause which only supports fields from the object specified in the FROM clause, WITH allows you to filter by other related criteria. For example, you can use the WITH clause to filter articles based on their classification in one or more data category groups. The WITH clause can only be used in the following cases:

  • To filter records based on their categorization. See WITH DATA CATEGORY filteringExpression.
  • To query and retrieve record changes tracked in a user profile feed. See UserProfileFeed in the Object Reference for Salesforce and Force.com.

If WITH is specified, the query only returns records that match the filter and are visible to the user. If unspecified, the query only returns the matching records that are visible to the user.

The filtering expression in the statements below is highlighted in bold. The syntax is explained in the following sections.

  • SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c
  • SELECT Id FROM UserProfileFeed WITH UserId='005D0000001AamR' ORDER BY CreatedDate DESC, Id DESC LIMIT 20