# The challenge of querying different levels of data at the same time **Category:** [AQL](https://discourse.openehr.org/c/aql/43) **Created:** 2024-09-10 03:39 UTC **Views:** 90 **Replies:** 6 **URL:** https://discourse.openehr.org/t/the-challenge-of-querying-different-levels-of-data-at-the-same-time/5685 --- ## Post #1 by @linforest Because the template is assembled using slots in multiple *Archetypes*, the data that should be *conceptually/logically* at the same level is *actually/structurally* at different levels, which makes it challenging to query the data at the same time (OR in a single ADL query/subquery), especially for those users who do not know the tree structure of the target template beforehand. ![image|631x500](upload://9gFztVAdtkTllICglABUj9uquKE.png) **Related Topic**: * [Physical activity archetypes; exercise, steps etc from apps & devices](https://discourse.openehr.org/t/physical-activity-archetypes-exercise-steps-etc-from-apps-devices/983) --- ## Post #2 by @sebastian.iancu Hi, It is not very clear from your post what is challenging/difficult. Perhaps try to explain more on what did with examples, or what you intended to query or find out, how was therefore the AQL query looking, what was your (initial) expectation on writing the query (especially what was challenging), etc. --- ## Post #3 by @linforest Hi @sebastian.iancu. Excuse me for my vague (even for myself) expression. Rethinking it carefully, what I wanted to express might be "that *would* be nice if the two groups of data points could be queried in a single ADL query using the same path". Actually, maybe it's not possible to write such an ADL query without specifying their full paths, just like the double slash (//) in an XPath expression "bookstore//book" which omits the *middle/intermediate paths*. I don't know if I made it clear this time? Thanks again. --- ## Post #4 by @damoca You can get similar results by retrieving all the ELEMENTs in AQL, independently of their path. (I don't know the exact archetype identifier in the example below) ``` SELECT elem FROM EHR e CONTAINS COMPOSITION c CONTAINS OBSERVATION o[openehr-EHR-OBSERVATION.Physical_activity.v1] CONTAINS ELEMENT elem ``` --- ## Post #5 by @sebastian.iancu Indeed, the `... CONTAINS bookstore CONTAINS book` is a search that in xPath would be equivalent to `booskstore//book` (so a 'descendant' relationship), and assuming all what you were looking is a `book`type, regardless the relationship level (child, grandchild, etc), then you will get what you are looking for. --- ## Post #6 by @linforest Ah, it's just what I want. And I can hardly wait to try this query... Thanks a lot, @damoca. [quote="damoca, post:4, topic:5685"] ``` SELECT elem FROM EHR e CONTAINS COMPOSITION c CONTAINS OBSERVATION o[openehr-EHR-OBSERVATION.Physical_activity.v1] CONTAINS ELEMENT elem ``` [/quote] This query works! Agian, thanks, @damoca. --- ## Post #7 by @linforest @sebastian.iancu Thank you for your clear and unambiguous description. --- **Canonical:** https://discourse.openehr.org/t/the-challenge-of-querying-different-levels-of-data-at-the-same-time/5685 **Original content:** https://discourse.openehr.org/t/the-challenge-of-querying-different-levels-of-data-at-the-same-time/5685