# Query of 2 databases

**URL:** <https://forum.inductiveautomation.com/t/query-of-2-databases/5894>\
**Category:** Ignition\
**Created:** [February 19, 2013, 12:28pm UTC](https://forum.inductiveautomation.com/t/query-of-2-databases/5894 "2013-02-19T12:28:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.laquidain](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@d.laquidain](https://forum.inductiveautomation.com/u/d.laquidain)\
**Post date:** [February 19, 2013, 12:28pm UTC](https://forum.inductiveautomation.com/t/query-of-2-databases/5894/1 "2013-02-19T12:28:47Z")

</div>

Hi,

I need a query to get datas from 2 diferent databases and later show them in a table. Does anybody know which is exactly the syntax in Ignition?

thanks!

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 20, 2013, 1:17am UTC](https://forum.inductiveautomation.com/t/query-of-2-databases/5894/2 "2013-02-20T01:17:07Z")

</div>

The problem is you can’t query two different databases in a single SQL query in binding unless the 2 databases are in the same database server. If they are not, you will have to generate the dataset in scripting. In scripting you can query two different databases and combine the results into one. The script would look something like this:[code]header = [“col1”, “col2”]  
data = []

rs = system.db.runQuery(“SELECT \* FROM FirstTable”)  
for row in rs:  
data.append([row[0], row[1]])

rs = system.db.runQuery(“SELECT \* FROM SecondTable”)  
for row in rs:  
data.append([row[0], row[1]])

newDS = system.dataset.toDataSet(header, data)[/code]You can run this script when the window opens or when someone presses a button or on a timer. I know this doesn’t give you exactly what you need so if you need more help please let us know.

---

<div class="post-metadata">

**Author:** ![d.laquidain](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@d.laquidain](https://forum.inductiveautomation.com/u/d.laquidain)\
**Post date:** [February 23, 2013, 8:36am UTC](https://forum.inductiveautomation.com/t/query-of-2-databases/5894/3 "2013-02-23T08:36:49Z")

</div>

Thanks Travis! Finall I’ve done it in a timer script and runs perfect.
