# How does one query across monthly data tables?

**URL:** <https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703>\
**Category:** Ignition\
**Created:** [February 22, 2017, 1:56pm UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703 "2017-02-22T13:56:35Z")\
**Posts on this page:** 8\
**Page:** 1

<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 22, 2017, 1:56pm UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/1 "2017-02-22T13:56:35Z")

</div>

I can’t find an explanation in the documentation.

If I write an SQL query I have to pass the table name. How do I ensure that I get records in preceding months (and future months when the time comes)?

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d5d78b4aafaad08760d6a3ff10ba6b46db6a44a6.png)

Many thanks.

---

<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 22, 2017, 3:47pm UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/2 "2017-02-22T15:47:56Z")

</div>

The [system.tag.queryTagHistory()](https://docs.inductiveautomation.com/display/DOC/system.tag.queryTagHistory) script function and [Tag History Binding](https://docs.inductiveautomation.com/display/DOC/Tag+History+Binding) take care of this for you. If you must write your own SQL, you will have to construct UNION statements for the tables yourself. You would construct the table names programmatically and duplicate your filter criteria for each table involved.

---

<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 22, 2017, 4:21pm UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/3 "2017-02-22T16:21:25Z")

</div>

Uggh!  
Thanks.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 25, 2017, 1:01am UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/4 "2017-02-25T01:01:35Z")

</div>

you can also manually query it

I slightly delved into this a couple years ago.

You can find it here

[inductiveautomation.com/forum/v … 70&t=13656](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=13656)

---

<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 25, 2017, 7:58am UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/5 "2017-02-25T07:58:29Z")

</div>

Thanks, diat150. I think I figured out a good way yesterday - see [inductiveautomation.com/forum/v … 94&t=16738](https://inductiveautomation.com/forum/viewtopic.php?f=94&t=16738).

The basic create a table to retrieve the required data from the historian. This solves all the problems of tagid, spanning multiple tables, data types, etc. Then write a script to examine / manipulate the returned dataset and feed that out to another table. The first table would be invisible in run mode. The Python code can be very simple.

---

<div class="post-metadata">

**Author:** ![AFULLER](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/afuller/32/7931_2.png) [@AFULLER](https://forum.inductiveautomation.com/u/AFULLER)\
**Post date:** [February 26, 2022, 12:54am UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/6 "2022-02-26T00:54:50Z")

</div>

Amazing that a software package like this cannot cross multiple tables without JOINS etc.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [February 26, 2022, 1:10am UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/7 "2022-02-26T01:10:47Z")

</div>

But it can with `system.tag.queryTagHistory` Its only if you want to write your own query that you are restricted to writing regular SQL queries with joins and such.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 26, 2022, 2:45am UTC](https://forum.inductiveautomation.com/t/how-does-one-query-across-monthly-data-tables/12703/8 "2022-02-26T02:45:19Z")

</div>

what you mean
