# How can I query historical data based on the value of specific tags

**URL:** <https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 5, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254 "2024-02-05T20:20:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pat\_Cunningham](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pat_cunningham/32/57710_2.png) [@Pat\_Cunningham](https://forum.inductiveautomation.com/u/Pat_Cunningham)\
**Post date:** [February 5, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/1 "2024-02-05T20:20:20Z")

</div>

How would I use system.tag.queryTagHistory and find a interval of data based on run number and status. ex. Run Number 9999 and status is running

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 5, 2024, 8:26pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/2 "2024-02-05T20:26:25Z")

</div>

The tag historian doesn't have any capability to search history by value(s).

Use the SQL Bridge module to record related variables together in one row in a dedicated table, add indices so those columns can be efficiently searched, and use ordinary SQL to perform the searches.

(You can script the equivalent of transaction groups if you do not want to buy the SQL Bridge module. Just more work on your part.)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 5, 2024, 10:19pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/3 "2024-02-05T22:19:15Z")

</div>

You can read about the Historian tables and data structure here.

[https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference](https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 5, 2024, 10:29pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/4 "2024-02-05T22:29:07Z")

</div>

> [@Transistor](#):
>
> Historian tables and data structure

That can help, but the resulting SQL will be horribly inefficient, unless adding indices throughout the data partitions (ewwww, crush your DB).

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 5, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/5 "2024-02-05T22:32:08Z")

</div>

Sorry, I wasn't promoting the Historian for this application. I meant to say that if one studies the table structure one can see why they're useless for this task (and many others). I didn't make it clear.

---

<div class="post-metadata">

**Author:** ![Pat\_Cunningham](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pat_cunningham/32/57710_2.png) [@Pat\_Cunningham](https://forum.inductiveautomation.com/u/Pat_Cunningham)\
**Post date:** [February 6, 2024, 12:42pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/6 "2024-02-06T12:42:53Z")

</div>

The historian data is strictly for trending display and if I want to query that data I should create my own data?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 6, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/7 "2024-02-06T12:50:24Z")

</div>

No, If you specifically want to trend data by _value_, then you will need to store the data by a method outside of the tag historian.

If you want to trend data by _date range_ then the Historian is designed for that.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 6, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/8 "2024-02-06T12:50:50Z")

</div>

See my thoughts: [Durations for certain tag value - #2 by Transistor](https://forum.inductiveautomation.com/t/durations-for-certain-tag-value/83586/2) and [Script about calculate the cumulative downtime - #7 by Transistor](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/7).

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 6, 2024, 12:57pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/9 "2024-02-06T12:57:43Z")

</div>

> [@lrose](#):
>
> No, If you specifically want to trend data by _value_, then you will need to store the data by a method outside of the tag historian.

I suppose I should include, you could spend a lot of time writing complex queries and indexing tables to make them efficient, but the provided `system.tag.queryTagHistory()` does not allow for querying the data by any means other than date and time.

---

<div class="post-metadata">

**Author:** ![Steve\_Laubach](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steve_laubach/32/60900_2.png) [@Steve\_Laubach](https://forum.inductiveautomation.com/u/Steve_Laubach)\
**Post date:** [February 6, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/10 "2024-02-06T13:41:21Z")

</div>

You could track transitions in run number and status to find date ranges for your tag history queries. Everything everyone told you about query tag history is correct.

I wouldn't use historical logging to track these transitions. I would use transactions.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 6, 2024, 1:46pm UTC](https://forum.inductiveautomation.com/t/how-can-i-query-historical-data-based-on-the-value-of-specific-tags/85254/11 "2024-02-06T13:46:56Z")

</div>

> [@Pat\_Cunningham](#):
>
> create my own data

Yes. Either by SQL Bridge transaction group or by script.
