# WHERE IN clause

**URL:** <https://forum.inductiveautomation.com/t/where-in-clause/12215>\
**Category:** Ignition\
**Created:** [October 8, 2016, 1:56pm UTC](https://forum.inductiveautomation.com/t/where-in-clause/12215 "2016-10-08T13:56:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Curlyandshemp](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Curlyandshemp](https://forum.inductiveautomation.com/u/Curlyandshemp)\
**Post date:** [October 8, 2016, 1:56pm UTC](https://forum.inductiveautomation.com/t/where-in-clause/12215/1 "2016-10-08T13:56:10Z")

</div>

Anyone use this before where the contents of IN are dynamic?  
I need to create a query where the contents of the WHERE IN (x,y,z) are the result of a another query. Only way I can figure out to do it is in scripting, where I have to build the contents of (x,y,z) with various strings.  
Is there a simplier way?

---

<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 8, 2016, 3:20pm UTC](https://forum.inductiveautomation.com/t/where-in-clause/12215/2 "2016-10-08T15:20:01Z")

</div>

Not really. To be really safe, you should construct a variable number of ‘?’ placeholders, then pass the appropriate length list of values in a Prep query. Bindings generally aren’t sufficiently flexible, which is why I created [objectScript()](https://www.automation-pros.com/simaids/doc/index.html), my generic “get out of jail free” card.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [October 8, 2016, 11:57pm UTC](https://forum.inductiveautomation.com/t/where-in-clause/12215/3 "2016-10-08T23:57:59Z")

</div>

If you aren’t manipulating the results of the other query you can do something like this.

`SELECT * 
FROM Table1
WHERE ID IN (SELECT ID FROM Table2)`

---

<div class="post-metadata">

**Author:** ![Curlyandshemp](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Curlyandshemp](https://forum.inductiveautomation.com/u/Curlyandshemp)\
**Post date:** [October 12, 2016, 3:12pm UTC](https://forum.inductiveautomation.com/t/where-in-clause/12215/4 "2016-10-12T15:12:17Z")

</div>

[quote=“jpark”]If you aren’t manipulating the results of the other query you can do something like this.

`SELECT * 
FROM Table1
WHERE ID IN (SELECT ID FROM Table2)`[/quote]

Thanks Jae,  
that worked for me :

[code]SELECT

```
a.t_stamp as 'Time',
b.Description as 'Tecnal Mold',
a.tank as 'Ferm Tank',
a.prodQty as 'Ferm Qty',
a.rennet/1000 as 'Rennet Inject',
a.runid

```

FROM

```
tecnal a
LEFT JOIN tecnalproducts b ON a.productID = b.id

```

WHERE RunID IN  
(SELECT  
a.ID

```
				FROM
					htstruns a

				WHERE
					Silo1ID = {Root Container.SiloID.value} OR
					Silo2ID = {Root Container.SiloID.value}	
			)

```

[/code]
