# Named Query with Transaction

**URL:** <https://forum.inductiveautomation.com/t/named-query-with-transaction/83999>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 9, 2024, 7:20pm UTC](https://forum.inductiveautomation.com/t/named-query-with-transaction/83999 "2024-01-09T19:20:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [January 9, 2024, 9:36pm UTC](https://forum.inductiveautomation.com/t/named-query-with-transaction/83999/5 "2024-01-09T21:36:50Z")

</div>

I know that the recommendation is "Use Named Queries", and a lot of the times that is a good answer, but in some cases (for instance this one), a prep query is really the better tool for the job.

Imagine a user selects 10 rows for deletion, do you really want to run 10 quries against the database when you can just run 1?

What about if 5 different users select 2 rows? or 5 rows.

You should really loop through the selected rows gathering all of the ids, and then run a single query.

Just like @pascal.fragnoud showed you here:

> [@GUI - Perspective - Confirm / Cancel popup](https://forum.inductiveautomation.com/t/gui-perspective-confirm-cancel-popup/83968/41):
>
> Any error message in your logs ? Try removing the project name. As @lrose said, you're using a regular transaction for named queries. Use a namedQueryTransaction. But I also agree with him: That's hardly transaction-worthy. If you're never rolling back... In this particular case, I'd probably just build the query dynamically and use runPrepUpdate just once. something like q = """ delete from your\_table where id in ({}) """.format(','.join('?' \* len(selRows))) system.db.runPrepUpdate(q, […

---

_[View the full topic](https://forum.inductiveautomation.com/t/named-query-with-transaction/83999)._
