> For the complete documentation index, see [llms.txt](https://docs.tricloudnexus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tricloudnexus.io/management-portal/insights/queries/creating-a-query.md).

# 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.
