# Creating a "Subquery" based on a Named Query

**URL:** <https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645>\
**Category:** Ignition\
**Tags:** namedqueries\
**Created:** [June 7, 2019, 4:04pm UTC](https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645 "2019-06-07T16:04:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [June 7, 2019, 4:04pm UTC](https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645/1 "2019-06-07T16:04:19Z")

</div>

The question here is if what I want to do is possible.

Say I have a Named Query called Query1. Query1 is quite complex and the data it returns would be re-used between other Named Queries.

Is it at all possible to make another Named Query (Query2) that operates on the data from Query1? The only option I can think of is using Query1 to create a database table and then have Query2 operate on that new table. I’m wondering if there’s another way to go about it, or some Ignition feature that I’m not aware of that allows for what I want to do.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 7, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645/2 "2019-06-07T16:11:51Z")

</div>

Each named query is independent of other named queries (and can’t see the cached results of other queries), so you’re right in thinking you need a place to store that intermediate result. Not sure if a table or a tag would be better – probably depends on your usage.

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [June 7, 2019, 4:12pm UTC](https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645/3 "2019-06-07T16:12:36Z")

</div>

I see, thank you!

---

<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:** [June 7, 2019, 6:00pm UTC](https://forum.inductiveautomation.com/t/creating-a-subquery-based-on-a-named-query/25645/4 "2019-06-07T18:00:21Z")

</div>

If this is a binding situation, you might want to take a look at my [view()](https://www.automation-pros.com/simaids/doc/expression.view.html) expression function, part of the [Simulation Aids Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids).
