# Query data from different tables in the SQL database

**URL:** <https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [October 27, 2017, 11:45am UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789 "2017-10-27T11:45:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [October 27, 2017, 11:45am UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/1 "2017-10-27T11:45:41Z")

</div>

Hi, I want to query data from different tables in the database, then display these data in the Table component by datetime , but ignition will Generate a table every month,like “sqlt\_data\_1\_2017\_10”,“sqlt\_data\_1\_2017\_09” , how query data from these table ,maybe I want query 1 year .

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 27, 2017, 12:04pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/2 "2017-10-27T12:04:37Z")

</div>

What about just using [system.tag.queryTagHistory](https://docs.inductiveautomation.com/display/DOC79/system.tag.queryTagHistory)?

It already traverses the partitions for you and returns a dataset which you can plug into your table component.

---

<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:** [October 27, 2017, 12:30pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/3 "2017-10-27T12:30:57Z")

</div>

Or you can just use a Tag History Binding, as described [here](https://docs.inductiveautomation.com/display/DOC79/Tag+Historian+and+Tables) and [here](https://docs.inductiveautomation.com/display/DOC79/Tag+History+Binding).

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [October 27, 2017, 12:44pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/4 "2017-10-27T12:44:10Z")

</div>

thanks, I use this script:  
endTime = system.date.now()  
startTime = system.date.addMinutes(endTime, -30)  
system.tag.queryTagHistory(paths=[‘Press\_Hiset’], startDate = startTime,endDate = endTime, returnSize=1, aggregationMode=“Maximum”, returnFormat=‘Wide’)

there is a error : syntax error on token : ‘EQUAL’(Line 2 , Char 9)

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 27, 2017, 1:01pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/5 "2017-10-27T13:01:24Z")

</div>

I ran the script and did not get any errors. The error you posted sounds like a syntax problem though. Try getting this to work in the script console if you have not already.

---

<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:** [October 27, 2017, 1:29pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/6 "2017-10-27T13:29:21Z")

</div>

And don’t forget that `system.tag.queryTagHistory()` returns a dataset – you have to assign that to a variable or to a component’s dataset property.

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [October 31, 2017, 12:51pm UTC](https://forum.inductiveautomation.com/t/query-data-from-different-tables-in-the-sql-database/15789/7 "2017-10-31T12:51:17Z")

</div>

Thank you! It’s work ok
