# AQL - same logical AQL with different syntax

**URL:** https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366
**Category:** AQL
**Tags:** aql
**Created:** [24 February 2020 18:29 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366 "2020-02-24T18:29:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![bna](https://discourse.openehr.org/user_avatar/discourse.openehr.org/bna/32/1994_2.png) [@bna](https://discourse.openehr.org/u/bna)
#### Post date: [24 February 2020 18:29 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/1 "2020-02-24T18:29:57Z")

</div>

What do you think about the following logic related to AQL?

The following AQLs will be intepreted as **logical equals for the AQL engine**. The first AQL 1.0 is a short hand query for the full AQL defined as AQL 1.3.

The examples is given here: [openehr-conformance/aql/index.adoc at master · bjornna/openehr-conformance · GitHub](https://github.com/bjornna/openehr-conformance/blob/master/aql/index.adoc#case-1)

> AQL 1.0  
> select o from OBSERVATION o[openEHR-EHR-OBSERVATION.lab\_test-result.v1]

> AQL 1.1  
> select o from COMPOSITION c  
> CONTAINS OBSERVATION o[openEHR-EHR-OBSERVATION.lab\_test-result.v1]

> AQL 1.2  
> select o from EHR e  
> CONTAINS COMPOSITION c  
> CONTAINS OBSERVATION o[openEHR-EHR-OBSERVATION.lab\_test-result.v1]

> AQL 1.3  
> select o from EHR e  
> CONTAINS VERSIONED\_COMPOSITION vo  
> CONTAINS VERSION v[latest\_version]  
> CONTAINS COMPOSITION c  
> CONTAINS OBSERVATION o[openEHR-EHR-OBSERVATION.lab\_test-result.v1]

---

<div class="post-metadata">

### Author: ![sebastian.iancu](https://discourse.openehr.org/user_avatar/discourse.openehr.org/sebastian.iancu/32/31_2.png) [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)
#### Post date: [24 February 2020 20:37 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/2 "2020-02-24T20:37:40Z")

</div>

I’m sorry, but I’m not sure what is the question (the catch) here. Can you rephrase it?

---

<div class="post-metadata">

### Author: ![bna](https://discourse.openehr.org/user_avatar/discourse.openehr.org/bna/32/1994_2.png) [@bna](https://discourse.openehr.org/u/bna)
#### Post date: [24 February 2020 21:20 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/3 "2020-02-24T21:20:37Z")

</div>

Sorry for being unclear 🙂

The question is if you agree that the given AQL’s will produce identical results. The given AQLs are, in our opinion, equal. They are different syntactic variants of the same maximal AQL given in AQL 1.3.

Take a look at the [original page](https://github.com/bjornna/openehr-conformance/blob/master/aql/index.adoc#case-1) for more details about the example, and also some more advanced examples covering the same kind of queires.

We came up with this when discussing the expected outcome from some AQL’s like example 1.0. And it got clear for us that we had to write the AQL out to the complete form to agree on what the expected result should be.

So again: Do you agree that AQL 1.0,1.1, 1.2 and 1.3 are identical on the logical level? If yes - is the same true also for 2.0, 2.1, 2.2 and 2.3?

---

<div class="post-metadata">

### Author: ![Seref](https://discourse.openehr.org/user_avatar/discourse.openehr.org/seref/32/13_2.png) [@Seref](https://discourse.openehr.org/u/Seref)
#### Post date: [25 February 2020 09:56 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/4 "2020-02-25T09:56:23Z")

</div>

they are all equal assuming the most common interpretation of CONTAINS semantics, which you’ve made explicit in 1.3.

---

<div class="post-metadata">

### Author: ![sebastian.iancu](https://discourse.openehr.org/user_avatar/discourse.openehr.org/sebastian.iancu/32/31_2.png) [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)
#### Post date: [25 February 2020 10:59 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/5 "2020-02-25T10:59:01Z")

</div>

They look functionally equivalent (or at least quite close) to me.

But I have few small questions:

- one is about not using “EHR e”, is that allowed? will that assume there is an EHR somewhere in the context? or is it implying all EHR available on system?
- in the AQL there is nothing like VERSIONED\_COMPOSITION, but just VERSIONED\_OBJECT, is that all correct?

---

<div class="post-metadata">

### Author: ![Seref](https://discourse.openehr.org/user_avatar/discourse.openehr.org/seref/32/13_2.png) [@Seref](https://discourse.openehr.org/u/Seref)
#### Post date: [25 February 2020 15:46 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/6 "2020-02-25T15:46:10Z")

</div>

syntactically, not having EHR is OK. We have a dedicated… “festival” going on regarding the definition of FROM, as you know 🙂

The syntax of AQL currently requires that you have a single root in the FROM clause, as in FROM X…

Again syntactically, that X can be any RM type with/without attribute constraints. Whether or not it is allowed, that’s what needs to go into AQL specification. Same for VERSIONED\_COMPOSITION, currently it is unspecified as far as I know.

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [25 February 2020 21:50 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/7 "2020-02-25T21:50:49Z")

</div>

> [@bna](#):
>
> CONTAINS VERSION v[latest\_version]

Is ‘latest\_version’ predicate supported by AQL?

---

<div class="post-metadata">

### Author: ![bna](https://discourse.openehr.org/user_avatar/discourse.openehr.org/bna/32/1994_2.png) [@bna](https://discourse.openehr.org/u/bna)
#### Post date: [25 February 2020 21:55 UTC](https://discourse.openehr.org/t/aql-same-logical-aql-with-different-syntax/366/8 "2020-02-25T21:55:36Z")

</div>

> [@pablo](#):
>
> Is ‘latest\_version’ predicate supported by AQL?

We assume so:

```auto
//<VersionPredicateOptions> ::= 'latest_version' | 'all_versions'
versionPredicateOptions
	: 'latest_version' | ALL_VERSIONS;

```

[See AQL syntax specification](https://specifications.openehr.org/releases/QUERY/latest/AQL.html#_aql_syntax_specification)
