# NamedQuery Not Running Multiple Queries

**URL:** <https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [October 24, 2024, 6:06am UTC](https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708 "2024-10-24T06:06:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sray\_Tech](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Sray\_Tech](https://forum.inductiveautomation.com/u/Sray_Tech)\
**Post date:** [October 24, 2024, 6:06am UTC](https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708/1 "2024-10-24T06:06:59Z")

</div>

SET @new\_id = 0;

UPDATE usertable  
SET id = (@new\_id := @new\_id + 1)  
ORDER BY id;

I am trying to run this Query, Also I have tried to run several other named queries which has two or more queries, but no one runs. Only single Query is running in one named query.

Please help.

 ![NamedQuery Error](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/c/ccfa4a5a0702e122d649dda5532317e01dd625af.png)

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [October 24, 2024, 7:30am UTC](https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708/2 "2024-10-24T07:30:18Z")

</div>

Hi,

See the below post, I know you are using a NamedQuery but the same applies :

> [@PrepQuery with SQL Variable](https://forum.inductiveautomation.com/t/prepquery-with-sql-variable/66509/4):
>
> Do note that using SQL variables is SQL scripting, which isn't actually in the JDBC spec. Some drivers allow it, but you really shouldn't be doing that if you want your work to be portable. Single statements for JDBC. Scripts belong in stored procedures.

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [October 24, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708/3 "2024-10-24T12:20:37Z")

</div>

If you are updating a record, you need a WHERE clause instead of an ORDER BY clause.  
An UPDATE statement without a WHERE clause will update every row in the table to have an ID of 1 (0 + 1).  
If you really want to update every row in the table (I'm guessing you want each row to have a unique ID), you'll need to add a subquery complication or do some looping.  
ORDER BY is used in SELECT statements that retrieve multiple rows.  
You can check your SQL directly in the database or use Ignition's

> Tools / Database Query Browser

and make sure your query works in the native environment before writing it into a NamedQuery.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 24, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/namedquery-not-running-multiple-queries/97708/4 "2024-10-24T12:22:08Z")

</div>

If you need a SQL Script to run your best bet is putting it into a stored procedure and calling that stored procedure from the named query or via scripting.
