# SYNTAX: Jython SQL Scripting: SELECT \* FROM (table) WHERE x = 1 AND y = 2

**URL:** <https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539>\
**Category:** Ignition\
**Created:** [March 22, 2019, 4:23pm UTC](https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539 "2019-03-22T16:23:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [March 22, 2019, 4:23pm UTC](https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539/1 "2019-03-22T16:23:24Z")

</div>

Hello,  
I want to use a complex WHERE statement and I am having trouble finding anything about syntax, I can successfully do it on one condition, I just get jammed up on the second condition.

my code:  
system.db.runPrepUpdate(""" DELETE FROM PanelShop.dbo.ActiveList WHERE (?) in (PONum) AND (?) in (JobNum)""", [myValue, ‘{Root Container.Power Table.SelectedJobNum}’])

I have tried several variations, such as;

WHERE (?,?) in (PONum, JobNum)

WHERE (?,?) in (PONum AND JobNum)

Does anyone know the correct syntax?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2019, 5:11pm UTC](https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539/2 "2019-03-22T17:11:44Z")

</div>

> [@ethanrendlen](#):
>
> `‘{Root Container.Power Table.SelectedJobNum}’`

You can't use the curly-brace relative reference syntax in scripting - only in expressions. Depending on where you're running this code (say, a button's `actionPerformed` event) your property reference would be something like `event.source.getParent().getComponent("Power Table").SelectedJobNum` to read the same property.

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [March 22, 2019, 5:37pm UTC](https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539/3 "2019-03-22T17:37:25Z")

</div>

Thank you for the response PGriffith, could you weigh in on the syntax of the query?  
Thank you either way.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2019, 5:53pm UTC](https://forum.inductiveautomation.com/t/syntax-jython-sql-scripting-select-from-table-where-x-1-and-y-2/23539/4 "2019-03-22T17:53:17Z")

</div>

> [@ethanrendlen](#):
>
> system.db.runPrepUpdate(""" DELETE FROM PanelShop.dbo.ActiveList WHERE (?) in (PONum) AND (?) in (JobNum)""", [myValue, ‘{Root Container.Power Table.SelectedJobNum}’])

You probably want to just use `where <col> = <value>`, not an `in` comparison; that is normally used to check membership of or in a list of values. Also, when using triple quotes, you can break your query out onto multiple lines, which I like for future readability:

```auto
query = """
DELETE 
FROM 
	PanelShop.dbo.ActiveList 
WHERE 
	PONum = ? 
	AND JobNum = ?
"""

args = [myValue, event.source.rootContainer.getComponent("Power Table").SelectedJobNum]

system.db.runPrepUpdate(query, args)

```
