# Dataset value fetch based on column value

**URL:** <https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931>\
**Category:** Ignition\
**Tags:** ignition80, ignition81, perspective, scripting\
**Created:** [February 9, 2022, 6:25pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931 "2022-02-09T18:25:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [February 9, 2022, 6:25pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/1 "2022-02-09T18:25:31Z")

</div>

Hello there,

I need help on below scenario:

I’ve a dataset (returning from query) of 2 columns. First column contains duplicate values and other column contains unique values like below.

Col1 Col2  
Abc 100  
Abc 101  
Abc 102  
Xyz 200  
Xyz 102  
Xyz 201  
Xyz 202

So how do I do select only values from col2 which has Abc in col1. There’s this huge data of around 20-25k rows.  
I know I could do this easily with query like below:  
SELECT col2 FROM tbl  
WHERE col1 = Abc

But I need to know how to do it with dataset function.

Another thing I’d like to know is, is it possible to merge a rows here?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 9, 2022, 6:39pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/2 "2022-02-09T18:39:09Z")

</div>

What DB flavor are you using? In mySQL/MariaDB, You can aggregate col2 into a single string like this

```auto
SELECT Col1, GROUP_CONCAT(Col2)
FROM Table
GROUP BY Col1

```

which yields

```auto
'Abc' | '100,101,102'

```

You could also make the dataset a pyDataset and `for` loop it and append to a list every time `col1` = ‘Abc’

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [February 9, 2022, 6:41pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/3 "2022-02-09T18:41:58Z")

</div>

I’m using MSSQL for this but I am trying to make this all at view side rather than through query.

Yes i know about pyDataset one but looking for other approaches to do the same. PyDataset loop takes time to return the result, around 10-15 seconds for huge data and more

---

<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 9, 2022, 6:45pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/4 "2022-02-09T18:45:45Z")

</div>

I am wondering why you don’t want to do this with a query. By not going the query route you are going to be processing your large amount of data twice which is going to take more time. Another possibility is to create a View in your database, but that pretty much doing the same thing as a query.

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [February 9, 2022, 6:47pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/5 "2022-02-09T18:47:36Z")

</div>

I’m avoiding to go with query because the dataset I’m returning is fetched from different sources using multiple cursor functions. That puts this combined value in temp table all together in the temporary table and returns it as my result dataset

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 9, 2022, 6:51pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/6 "2022-02-09T18:51:56Z")

</div>

@pturmel has a `Simulation Aids` Module that is free and includes an expression function that can search a dataset like a query called `view()`

> [@Filter in table](https://forum.inductiveautomation.com/t/filter-in-table/53282/2):
>
> The tag historian doesn’t offer that feature built-in. You will need to move the binding to a custom property and perform the filtering action yourself. You can do this with a script, but for convenience I recommend the [view()](https://www.automation-pros.com/simaids/doc/expression.view.html) expression function from my free [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module. You would bind the original table’s data property with an expression like this: view("Select \* Where someColumn==someConstant", {Root Container.path.to.custom.prop})

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [February 9, 2022, 6:54pm UTC](https://forum.inductiveautomation.com/t/dataset-value-fetch-based-on-column-value/55931/7 "2022-02-09T18:54:41Z")

</div>

Thanks man, that seems to help!
