> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/investigate-and-respond-to-incidents/build-xql-queries/how-to-build-xql-queries.md).

# How to build XQL queries

{% hint style="info" %}

### Notice

Building Cortex Query Language (XQL) queries in the Query Builder requires a Cortex XDR Pro license.
{% endhint %}

The Cortex Query Language (XQL) enables you to query data ingested into Cortex XDR for rigorous endpoint and network event analysis returning up to 1M results. To help you create an eﬀective XQL query with the proper syntax, the query ﬁeld in the user interface provides suggestions and deﬁnitions as you type.

XQL forms queries in stages. Each stage performs a specific query operation and is separated by a pipe character (|). Queries require a dataset, or data source, to run against. Unless otherwise specified, the query runs against the **`xdr_data`** dataset, which contains all log information that Cortex XDR collects from all Cortex product agents, including EDR data, and PAN NGFW data. In XDM queries, you must specify the dataset mapped to the XDM that you want to run your query against.

{% hint style="info" %}

### Important

Forensic datasets are not inlcuded by default in XQL query results, unless the dataset query is explicitly defined to use a forensic dataset.
{% endhint %}

<details>

<summary>Dataset query syntax</summary>

In a dataset query, unless otherwise specified, the query runs against the `xdr_data` dataset, which contains all log information that Cortex XDR collects from all Cortex product agents, including EDR data, and PAN NGFW data. In a dataset query, if you are running your query against a dataset that has been set as default, there is no need to specify a dataset. Otherwise, specify a dataset in your query. The Dataset Queries lists the available datasets, depending on system configuration.

{% hint style="info" %}

### Note

* Users with different dataset permissions can receive different results for the same XQL query.
* An administrator or a user with a predefined user role can create and view queries built with an unknown dataset that currently does not exist in Cortex XDR. All other users can only create and view queries built with an existing dataset.
* When you have more than one dataset or lookup, you can change your default dataset by navigating to **Settings** → **Configurations** → **Data Management** → **Dataset Management**, right-click on the appropriate dataset, and select **Set as default**. For more information about setting default datasets, see [Dataset management](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/data-management/dataset-management.md).
  {% endhint %}

The basic syntax structure for querying datasets that are not mapped to the XDM is:

```programlisting
dataset = <dataset name> 
    | <stage1> ...
    | <stage2> ... 
    | <stage3> ...
```

or

```programlisting
dataset in (<dataset name>)
    | <stage1> ...
    | <stage2> ...
    | <stage3> ...
```

You can specify a dataset using one of the following formats, which is based on the data retention offerings available in Cortex XDR.

* Hot Storage queries use the format `dataset = <dataset name>`. This is the default option.

  Example:&#x20;

  ```programlisting
  dataset = xdr_data
  ```
* Cold Storage queries use the format `cold_dataset = <dataset name>`.

  Example:&#x20;

  ```programlisting
  cold_dataset = xdr_data
  ```

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>You can build a query that investigates data in both a cold dataset and a hot dataset in the same query. In addition, as the hot storage dataset format is the default option and represents the fully searchable storage, this format is used throughout this guide for investigation and threat hunting. For more information on hot and cold storage, see <a href="/pages/NCY31Uu2RenjaU42HyGw">Dataset management</a>.</p></div>

When using the hot storage default format, this returns every `xdr_data` record contained in your Cortex XDR instance over the time range that you provide to the Query Builder user interface. This can be a large amount of data, which may take a long time to retrieve. You can use a `limit` stage to specify how many records you want to retrieve.

There is no practical limit to the number of stages that you can specify. See [Stages](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/stages.md) for information on all the supported stages.

In the `xdr_data` dataset, every user ﬁeld included in the raw data for network, authentication, and login events has an equivalent normalized user ﬁeld associated with it that displays the user information in the following standardized format:

`<company domain>\<username>`

For example, the `login_data` ﬁeld has the `login_data_dst_normalized_user` ﬁeld to display the content in the standardized format. To ensure the most accurate results, we recommend that you use these `normalized_user` ﬁelds when building your queries.

</details>

<details>

<summary>Additional components</summary>

XQL queries can contain different components, such as functions and stages, depending on the type of query you want to build.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/investigate-and-respond-to-incidents/build-xql-queries/how-to-build-xql-queries.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
