# Creating a Query

***

### Creating your first Query

If you are in doubt were to find the Query editor or how to select a Database, please see [Queries](/management-portal/insights/queries.md).

1. **Familiarize yourself with KQL**:

   * The Query Editor uses KQL (Kusto Query Language) to query data. If you're new to KQL, refer to the [Queries](/management-portal/insights/queries.md#learning-kusto-query-language-kql)

   <figure><img src="/files/Ib3I63mzxjOYeUrRft6I" alt=""><figcaption><p>Select a database in the connection tree to the left and write queries</p></figcaption></figure>
2. **Build Your Query**:
   * Use the query editor interface to type your KQL commands.
   * This Query will show the name all Asset Hierarchies that has been deployed to a device, and sort them alphabetically by the name of the Asset Hierarchy:

     ```kusto
     AssetHierarchy
     | distinct HierarchyName
     | order by HierarchyName asc
     ```
3. **Preview your Query**:
   * Click **Run** to execute the query and preview the results in the **Results** panel.

<figure><img src="/files/l45pPCZ2gSYi3c1ByOgP" alt=""><figcaption><p>Running your first Query</p></figcaption></figure>

***

### Build another Query

The query below tries to select 100 random measurements from the Database from the last 10 days.

```kusto
Measurements
| where StartTimestamp > ago(10d)
| take 100
```

This query will only return data, if a deployment to an Edge device has been done, and the Edge device has collected data from one or more data connections within the last 10 days.

<figure><img src="/files/LMTuCt7Arw9xDJzFNW7v" alt=""><figcaption><p>Query returns some Measurments</p></figcaption></figure>

***

### Query specific Tag measurements

From the query you ran before, try and copy the **HierarchicalName** from one of the Measurements in the Table, and then insert the name in the query below, where it says \<insert hierarchical name here>.

```kusto
Measurements
| where StartTimestamp between (ago(10d) .. now())
| where HierarchicalName has "<insert hierarchical name here>"
| order by StartTimestamp asc
| limit 5000
```

The Query selects datapoints from the last 10 days from the chosen Tag (HierarchicalName). It orders the Measurements by its StartTimestamp in ascending order, then takes the first 5000 data points.

<figure><img src="/files/aHp7vHH2bQfVWz51clBQ" alt=""><figcaption></figcaption></figure>

For more Queries please see:

* [Basic Queries](/management-portal/insights/queries/creating-a-query/basic-queries.md) Basic operators
* [Intermediate Queries](/management-portal/insights/queries/creating-a-query/intermediate-queries.md) Join, Summarize and make-series operators
* [Advanced Queries](/management-portal/insights/queries/creating-a-query/advanced-queries.md) Trendline and Forecasting

For more details on KQL, please see [Kusto Query Language](https://learn.microsoft.com/en-us/kusto/query/syntax-conventions?view=azure-data-explorer\&preserve-view=true) in Microsoft's documentation.


---

# Agent Instructions: 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:

```
GET https://docs.tricloudnexus.io/management-portal/insights/queries/creating-a-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
