---
schema_version: "1"
id: 7d61a2b6eb75aa7201cd33be166f39f84fcc62aec203d9f58a8a1eadedde1133
title: WITH DATA CATEGORY
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/knowledge/guides/sforce-api-calls-soql-select-with-datacategory.md
canonical_url: https://developer.salesforce.com/docs/service/salesforce-knowledge-dev-guide/guide/sforce-api-calls-soql-select-with-datacategory.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 87f4a0457f14e4dc2936e9eb27d55f3bfb8bae2b2e423599f9d4581305155edc
products:
  - Salesforce Knowledge Developer Guide
  - Service Cloud Developer Content
---

# WITH DATA CATEGORY

You can search for Salesforce Knowledge articles and questions by their data category in a SOQL query. `WITH DATA CATEGORY` is an optional clause in a `SELECT` statement that’s used to filter records that are associated with one or more data categories and are visible to users.

```soql
[WITH [DATA CATEGORY] filteringExpression]
```

If `WITH DATA CATEGORY` is specified, the `query()` returns only matching records that are associated with the specified data categories and are visible to the user. If unspecified, the `query()` only returns the matching records that are visible to the user.

**important:** `CategoryData` is an object and DATA CATEGORY is syntax in a SOQL `WITH` clause. `WITH DATA CATEGORY` is valid syntax, but `WITH CategoryData` is not supported.

A SOQL statement using a `WITH DATA CATEGORY` clause must also include a `FROM {ObjectTypeName}` clause where _ObjectTypeName_ equals:

- `KnowledgeArticleVersion` to query all article types
- an article type `API Name` to query a specific article type
- `Question` to query questions

When _ObjectTypeName_ equals to [KnowledgeArticleVersion](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_knowledgearticleversion.htm) or any article type `API Name` in the `FROM` clause, a `WHERE` clause must be specified with one of the following parameters:

- PublishStatus to query articles depending on their status in the publishing cycle:
  - `WHERE PublishStatus='online'` for published articles
  - `WHERE PublishStatus='archived'` for archived articles
  - `WHERE PublishStatus='draft'` for draft articles
- Id to query an article based on its id

For information on article types or questions, see “Knowledge Article Types” in Salesforce Help.

**note:** The `WITH DATA CATEGORY` clause does not support [bind variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm). The clause can have no more than three data category conditions.

## _filteringExpression_

The _filteringExpression_ in the `WITH DATA CATEGORY` clause uses the following syntax:

```soql
DATACATEGORYSELECTION [AND [DATACATEGORYSELECTION][...]

```

The examples in this section are based on the following data category group:

```nolang
Geography__c
    ww__c
        northAmerica__c
            usa__c
            canada__c
            mexico__c
        europe__c
            france__c
            uk__c
        asia__c
```

The category filtering in the statements is noted.

- `SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c`
  - Where the filter is `WITH DATA CATEGORY Geography__c ABOVE usa__c`
- `SELECT Title FROM Question WHERE LastReplyDate > 2005-10-08T01:02:03Z WITH DATA CATEGORY Geography__c AT (usa__c, uk__c)`
  - Where the filter is `WITH DATA CATEGORY Geography__c AT (usa__c, uk__c)`
- `SELECT UrlName FROM KnowledgeArticleVersion WHERE PublishStatus='draft' WITH DATA CATEGORY Geography__c AT usa__c AND Product__c ABOVE_OR_BELOW mobile_phones__c`
  - Where the filter is `WITH DATA CATEGORY Geography__c AT usa__c AND Product__c ABOVE_OR_BELOW mobile_phones__c`

You can only use the `AND` logical operator. The following syntax is incorrect as `OR` is not supported:

```soql
WITH DATA CATEGORY Geography__c ABOVE usa__c OR Product__c AT mobile_phones__c
```
