# Joining two ignition tables (not sql tables)

**URL:** <https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [October 2, 2020, 7:13am UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296 "2020-10-02T07:13:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anuragrattan23](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@anuragrattan23](https://forum.inductiveautomation.com/u/anuragrattan23)\
**Post date:** [October 2, 2020, 7:13am UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/1 "2020-10-02T07:13:25Z")

</div>

Hello there,

I have two table son one ignition window. I am trying to join the two tables but getting the error- Invalid object name for tables. How do I select the columns if there is an error finding the table itself?

Any help? Below is the error

===  
Exception: Error running query:  
SQLQuery(query=SELECT IDandName.FaultName,  
IDandCount.FaultCount  
FROM IDandCount  
INNER JOIN IDandName ON IDandCount.FaultID = IDandName.FaultID, database=MORPSQL\_Ignite)@0ms  
On: CIPFaults.Root Container.NameAndCount.data  
caused by GatewayException: Invalid object name ‘IDandCount’.  
caused by SQLServerException: Invalid object name ‘IDandCount’.

Ignition v7.9.7 (b2018032914)  
Java: Oracle Corporation 1.8.0\_231

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 2, 2020, 10:34am UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/2 "2020-10-02T10:34:16Z")

</div>

Are you trying to run a query on a vision table? That is not possible to do. You need to iterate through the data properties of the tables.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 2, 2020, 2:15pm UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/3 "2020-10-02T14:15:32Z")

</div>

To expand on Jordan’s answer, the data for your Vision tables is a dataset. You can append one dataset to another using [system.dataset.appendDataset()](https://docs.inductiveautomation.com/display/DOC80/system.dataset.appendDataset)

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [October 2, 2020, 2:15pm UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/4 "2020-10-02T14:15:51Z")

</div>

If you just want to combine the data from both tables into a single dataset, you can script a propertyChange event and append the datasets using [system.dataset.appendDataset()](https://docs.inductiveautomation.com/display/DOC80/system.dataset.appendDataset). This requires that both datasets columns match.

---

<div class="post-metadata">

**Author:** ![anuragrattan23](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@anuragrattan23](https://forum.inductiveautomation.com/u/anuragrattan23)\
**Post date:** [October 17, 2020, 5:34am UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/5 "2020-10-17T05:34:49Z")

</div>

Thanks guys. I have tried system.dataset.appendDataset() but it says there is an error in Line1 char6, which is “.”. I really don’t understand this error.  
I have these two tables (see screenshot) and I need to create a 3rd table with columns FaultName and FaultCount. It is simple if the tables are SQL tables as you can access the columns. But ignition tables doesn’t have column selection. And appendDataset not working as well. Any ideas? Can it be achieved in ignition at all?

Thank you in advance.

 ![Faults tables](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/f/6f715fe1d7b96deea236a862b596b45c2ae579e6.png)

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [October 17, 2020, 11:16am UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/6 "2020-10-17T11:16:37Z")

</div>

Off the top of my head.  
Will be better with list comprehension but this will get you started.

```auto
ds1 = system.dataset.toPyDataSet(event.source.parent.getComponent('Power Table').data)
ds2 = system.dataset.toPyDataSet(event.source.parent.getComponent('Power Table 1').data)
tbl = event.source.parent.getComponent('Power Table 2')
ds3 = []
hdr=['faultID','FaultName','FaultCount']
for x in ds1:
	for f in ds2:
		if f[0]==x[0]:
			ds3.append([x[0],x[1],f[1]])
tbl.data = system.dataset.toDataSet(hdr,ds3)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 17, 2020, 10:23pm UTC](https://forum.inductiveautomation.com/t/joining-two-ignition-tables-not-sql-tables/39296/7 "2020-10-17T22:23:52Z")

</div>

It would be more efficient to make a dictionary out of the first dataset for lookups.

```python
headers1 = ['FaultID', 'FaultName']
data1 = [[1, 'Return Temp Alarm Low Low'],
            [2, 'Return Alarm Temp High High'],
            [3, 'STOP Command'],
            [4, 'Caustic Tank Level Low Low'],
            [5, 'Acid Tank Level Low Low']
           ]
headers2 = ['FaultID', 'FaultCount']
data2 = [[3, 543],
            [2, 210],
            [4, 98],
            [1, 76],
            [5, 5]
           ]
           
ds1 = system.dataset.toPyDataSet(system.dataset.toDataSet(headers1, data1))
ds2 = system.dataset.toPyDataSet(system.dataset.toDataSet(headers2, data2))
#print '-- ds1 --'          
#util.printDataSet(ds1)
#print '-- ds2 --'
#util.printDataSet(ds2)

lookup = {row['FaultID']:row['FaultName'] for row in ds1}

headersOut = ['FaultID', 'FaultName', 'FaultCount']
dataOut = [[row['FaultID'], lookup[row['FaultID']], row['FaultCount']] for row in ds2]

dsOut = system.dataset.toDataSet(headersOut, dataOut)
#print '-- dsOut --'
#util.printDataSet(dsOut)

```

Output:

```nohighlight
-- ds1 --
row | FaultID | FaultName                  
-------------------------------------------
0 | 1 | Return Temp Alarm Low Low  
1 | 2 | Return Alarm Temp High High
2 | 3 | STOP Command               
3 | 4 | Caustic Tank Level Low Low 
4 | 5 | Acid Tank Level Low Low    
-- ds2 --
row | FaultID | FaultCount
--------------------------
0 | 3 | 543       
1 | 2 | 210       
2 | 4 | 98        
3 | 1 | 76        
4 | 5 | 5         
-- dsOut --
row | FaultID | FaultName | FaultCount
--------------------------------------------------------
0 | 3 | STOP Command | 543       
1 | 2 | Return Alarm Temp High High | 210       
2 | 4 | Caustic Tank Level Low Low | 98        
3 | 1 | Return Temp Alarm Low Low | 76        
4 | 5 | Acid Tank Level Low Low | 5         

```
