query writing question 2 (Seref Arikan)

Oh, sorry. I have indeed used the wrong alias in the example. I intended to write

SELECT a/data[at0001]/items[at0004]/value
FROM EHR e CONTAINS COMPOSITION a[openEHR-EHR-COMPOSITION.encounter.v1]
WHERE a/data[at0001]/items[at0004]/value/value >= 140

What ensures that the identified path in the SELECT section references
the same data instances that are contrained with the same identified
path in the WHERE section ?

Greetings
Georg

Simply put, the semantics of AQL. that ‘a’ means the same node in SELECT and WHERE clauses. Now, there may be > 1 node at a relative path (a/…/node) but even then, the semantics of AQL requires that the SELECT and WHERE clauses apply to the exact same data node. Where there is > 1, you’ll see the result set contain a row for each, but SELECT and WHERE will always apply to the same node. it is the implementer’s responsibility to ensure that this semantics holds.