# View() Function Multiple WHERE conditions

**URL:** <https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [December 17, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934 "2024-12-17T15:45:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norey\_Latona](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Norey\_Latona](https://forum.inductiveautomation.com/u/Norey_Latona)\
**Post date:** [December 17, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/1 "2024-12-17T15:45:28Z")

</div>

I have successfully loaded the Simulation Aids and use the view() function to query a dataset and return values successfully. However, I would like to use a second filter in the WHERE clause

something Like: ... WHERE Location=='WHSE' AND UNIT=='U2' ...sort of thing.

IS this possible or am I limited to only one WHERE condition?

---

<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:** [December 17, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/2 "2024-12-17T16:16:59Z")

</div>

You can use as many as you want. Be sure to use `args` to reference any dynamic comparison values. Note that the entire expression after WHERE must be valid **python** , so use a lower case `and`.

Also, for anything other than pivot operations (which are only implemented in `view()`), the newer iteration functions are much more performant.

---

<div class="post-metadata">

**Author:** ![Norey\_Latona](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Norey\_Latona](https://forum.inductiveautomation.com/u/Norey_Latona)\
**Post date:** [December 17, 2024, 4:52pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/3 "2024-12-17T16:52:32Z")

</div>

> [@pturmel](#):
>
> Note that the entire expression after WHERE must be valid **python** , so use a lower case `and`.

Thank you! Turns out the case was my only issue!

---

<div class="post-metadata">

**Author:** ![Norey\_Latona](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Norey\_Latona](https://forum.inductiveautomation.com/u/Norey_Latona)\
**Post date:** [December 18, 2024, 1:31pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/4 "2024-12-18T13:31:00Z")

</div>

pturmel -- I really appreciate the view() development tool you created.

I am new to the python environment--I have to admit that the use of the tool and the tuples was a little confusing to me however once I got my mind wrapped around it --it all clicked.

For anyone seeking clarification, the following 2 pieces of code yield equivalent results:

```python
view("select NOMINAL_RATE where LOCATION ==args[0] and ID==args[1]"
	,{[~]DATA/EXT/Rates},{[~]Ext/Unit1/Parameters.UnitID},{[~]Ext/Unit1/ID_Actual})

view("select NOMINAL_RATE where LOCATION =='"+{[~]Ext/Unit1/Parameters.UnitID}}+"' 
	and ID=='"+{[~]Ext/Unit1/ID_Actual}}+"'" 
	,{[~]DATA/EXT/Rates})

```

Note: The syntax using tuples is cleaner. The second example--I find easier (more intuitive) to read--but does have added punctuation to contend with --more prone to errors.

---

<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:** [December 18, 2024, 2:14pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/5 "2024-12-18T14:14:40Z")

</div>

> [@Norey\_Latona](#):
>
> equivalent results

Actually, they don't behave identically. The first version will compile its PseudoSQL **once** and will thereafter run very quickly. It also will work reliably regardless what your argument data types are.

The second version must compile on every execution, and will break if you try to use numeric columns, or if a value is passed that has a quote character in it.

---

<div class="post-metadata">

**Author:** ![Norey\_Latona](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Norey\_Latona](https://forum.inductiveautomation.com/u/Norey_Latona)\
**Post date:** [December 18, 2024, 2:31pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/6 "2024-12-18T14:31:29Z")

</div>

Thank you for the clarification! Those are very significant distinctions...details matter!

Tuples...all the way!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 18, 2024, 3:18pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/7 "2024-12-18T15:18:07Z")

</div>

Now that I have switched from the `view()` expression to the new iteration functions, I find it hard to read `view()` expressions, especially when they get more complex.

Phil can correct me if I am wrong, but I believe that either of the following two expressions would fundamentally return the same results but are more performat, and to my eye easier to read (but that's maybe just me).

Return in Dataset format:

```python
columnRearrange(
    where({[~]DATA/EXT/Rates},
        it()['LOCATION'] = {[~]Ext/Unit1/Parameters.UnitID},
        it()['ID'] = {[~]Ext/Unit1/ID_Actual}),
    'NOMINAL_RATE'
)

```

Return as a List (Array in Perspective Terms):

```python
transform(
    where({[~]DATA/EXT/Rates},
        it()['LOCATION'] = {[~]Ext/Unit1/Parameters.UnitID},
        it()['ID'] = {[~]Ext/Unit1/ID_Actual}),
    forEach(value(), it()['NOMINAL_RATE'])
)

```

---

<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:** [December 18, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/8 "2024-12-18T15:20:33Z")

</div>

> [@lrose](#):
>
> Phil can correct me

Just ditch the double-equals in expressions.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 18, 2024, 3:21pm UTC](https://forum.inductiveautomation.com/t/view-function-multiple-where-conditions/99934/9 "2024-12-18T15:21:31Z")

</div>

> [@pturmel](#):
>
> double-equals

oops. Great catch on my copy paste, no read.
