# dataCategorySelection

The syntax of the data category selection in a `WITH DATA CATEGORY` clause in a SOQL query includes a category group name to use as a filter, the filter selector, and the name of the category to use for filtering.

The *dataCategorySelection* uses the following syntax:

```soql
DATACATEGORYGROUPNAME FILTERINGSELECTOR DATACATEGORYNAME
```

| Syntax                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *dataCategoryGroupName* | The name of the data category group to use as a filter. `Geography__c` is the data category group in the following example. You cannot use the same data category group more than once in a query. For example, the following command is incorrect: `WITH DATA CATEGORY Geography__c ABOVE usa__c AND Geography__c BELOW europe__c`                                                                                                                                                                             |
| *filteringSelector*     | The selector used to filter the data in the specified data category. See [Filtering Selectors](#filtering-selectors) for a list of valid selectors.                                                                                                                                                                                                                                                                                                                                                             |
| *dataCategoryName*      | The name of the data category for filtering. You must have visibility on the category you specify. You can use parentheses to apply the filtering operator to more than one data category; each data category must be separated by a comma. For example: `WITH DATA CATEGORY Geography__c AT (usa__c,france__c,uk__c)`. You can't use the `AND` operator instead of parentheses to list multiple data categories. The following syntax does not work: `WITH DATA CATEGORY Geography__c AT usa__c AND france__c` |

## Filtering Selectors

When specifying filters for a `WITH DATA CATEGORY` clause of a SOQL query, you can use `AT` to select the specified category, `ABOVE` to select the category and all its parent categories, `BELOW` to select the category and all its subcategories, and `ABOVE_OR_BELOW` to select the category, its parent categories, and its subcategories.

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
```

This table lists the *filteringSelector* values that are used in the [*dataCategorySelection*](/docs/service/salesforce-knowledge-dev-guide/guide/sforce-api-calls-soql-select-with-datacategory-catselection.md) syntax.

| Selector         | Description                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------- |
| `AT`             | Select the specified data category.                                                       |
| `ABOVE`          | Select the specified data category and all its parent categories.                         |
| `BELOW`          | Select the specified data category and all its subcategories.                             |
| `ABOVE_OR_BELOW` | Select the specified data category, all its parent categories, and all its subcategories. |

Example for `AT` — selects `asia__c`:

```soql
WITH DATA CATEGORY Geography__c AT asia__c
```

Example for `ABOVE` — selects `usa__c`, `northAmerica__c`, and `ww__c`:

```soql
WITH DATA CATEGORY Geography__c ABOVE usa__c
```

Example for `BELOW` — selects `northAmerica__c`, `usa__c`, `canada__c`, and `mexico__c`:

```soql
WITH DATA CATEGORY Geography__c BELOW northAmerica__c
```

Example for `ABOVE_OR_BELOW` — selects `ww__c`, `europe__c`, `france__c`, and `uk__c`:

```soql
WITH DATA CATEGORY Geography__c ABOVE_OR_BELOW europe__c
```

Here are some more examples of WITH DATA CATEGORY clauses in a SELECT statement in a SOQL query.

| Type of Search                                                                                                                                                                                                                           | Examples                                                                                                                                                                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Select the title from all questions classified with the `mobile_phones__c` data category in the `Product__c` data category group                                                                                                         | `SELECT Title FROM Question WHERE LastReplyDate < 2005-10-08T01:02:03Z WITH DATA CATEGORY Product__c AT mobile_phones__c`                                                                     |
| Select the title and summary from all published Knowledge articles classified above or below `europe__c` in the `Geography__c` data category group and below `allProducts__c` in the `Product__c` data category group                    | `SELECT Title, Summary FROM KnowledgeArticleVersion WHERE PublishStatus='Online' AND Language = 'en_US' WITH DATA CATEGORY Geography__c ABOVE_OR_BELOW europe__c AND Product__c BELOW All__c` |
| Select the ID and title from draft articles of type "Offer__kav" classified with the `france__c`or`usa__c`data category in the`Geography__c`data category group and above the`dsl__c`data category in the`Product__` data category group | `SELECT Id, Title FROM Offer__kav WHERE PublishStatus='Draft' AND Language = 'en_US' WITH DATA CATEGORY Geography__c AT (france__c,usa__c) AND Product__c ABOVE dsl__c`                       |
