# AQL

**URL:** https://discourse.openehr.org/c/specifications/aql/43.md

[Latest](https://discourse.openehr.org/latest.md) · [Categories](https://discourse.openehr.org/categories.md) · [Tags](https://discourse.openehr.org/tags.md)

---

## [About the AQL category](https://discourse.openehr.org/t/about-the-aql-category/632)

<div class="topic-metadata">

**Author:** [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)\
**Replies:** 0

</div>

For discussions on the openEHR Archetype Query Language (AQL) specification. Please FORMAT your queries as MULTI-LINE!

---

## [Where do you keep the AQL's ?](https://discourse.openehr.org/t/where-do-you-keep-the-aqls/5052)

<div class="topic-metadata">

**Author:** [@david.alonso](https://discourse.openehr.org/u/david.alonso)\
**Replies:** 26\
**Last updated:** [19 October 2026 06:02 UTC](https://discourse.openehr.org/t/where-do-you-keep-the-aqls/5052 "2026-10-19T06:02:25Z")

</div>

We face with the need to store AQL’s to be able to provide them when necessary to different initiatives projects or actors. We are not sure where to store them. Has anyone else encountered this need? We would be very gr…

---

## [How to query for compositions where fields are not null](https://discourse.openehr.org/t/how-to-query-for-compositions-where-fields-are-not-null/5830)

<div class="topic-metadata">

**Author:** [@Lucas](https://discourse.openehr.org/u/Lucas)\
**Replies:** 7\
**Last updated:** [11 August 2026 10:52 UTC](https://discourse.openehr.org/t/how-to-query-for-compositions-where-fields-are-not-null/5830 "2026-08-11T10:52:40Z")

</div>

Context: In SQL I frequently use the “IS NOT NULL” operator, to constrain the search results of objects, where the given field is not null and thus not empty. I am currently trying the same thing with AQL, where I want…

---

## [Are AS aliases allowed in the WHERE clause](https://discourse.openehr.org/t/are-as-aliases-allowed-in-the-where-clause/17186)

<div class="topic-metadata">

**Author:** [@borut.jures](https://discourse.openehr.org/u/borut.jures)\
**Replies:** 0\
**Last updated:** [7 August 2026 11:58 UTC](https://discourse.openehr.org/t/are-as-aliases-allowed-in-the-where-clause/17186 "2026-08-07T11:58:57Z")

</div>

This comment prompted me to ask for clarification on whether AS aliases are allowed in the WHERE clause and if this is intended by the current wording in the AQL specifications: Usage of aliases in WHERE clauses is exp…

---

## [Proposal for a LET keyword in AQL](https://discourse.openehr.org/t/proposal-for-a-let-keyword-in-aql/17184)

<div class="topic-metadata">

**Author:** [@borut.jures](https://discourse.openehr.org/u/borut.jures)\
**Replies:** 7\
**Last updated:** [7 August 2026 11:11 UTC](https://discourse.openehr.org/t/proposal-for-a-let-keyword-in-aql/17184 "2026-08-07T11:11:17Z")

</div>

A SQL dialect I’m using to query openEHR, supports declaring variables with a LET keyword. It might be helpful to consider adding a similar keyword to AQL. For example this AQL query: SELECT o/data\[at0001\]/events\[at…

---

## [Is it possible to follow a link in AQL?](https://discourse.openehr.org/t/is-it-possible-to-follow-a-link-in-aql/6994)

<div class="topic-metadata">

**Author:** [@emmanuel.eschmann](https://discourse.openehr.org/u/emmanuel.eschmann)\
**Replies:** 25\
**Last updated:** [26 July 2025 15:20 UTC](https://discourse.openehr.org/t/is-it-possible-to-follow-a-link-in-aql/6994 "2025-07-26T15:20:32Z")

</div>

The locatable class provides a links attribute with which, for example, structures in other compositions can be referenced. We have tried to use a single AQL query to read a composition and, within the same AQL query, r…

---

## [Does AQL support regular expressions in comparison operators?](https://discourse.openehr.org/t/does-aql-support-regular-expressions-in-comparison-operators/6993)

<div class="topic-metadata">

**Author:** [@emmanuel.eschmann](https://discourse.openehr.org/u/emmanuel.eschmann)\
**Replies:** 1\
**Last updated:** [17 July 2025 23:07 UTC](https://discourse.openehr.org/t/does-aql-support-regular-expressions-in-comparison-operators/6993 "2025-07-17T23:07:46Z")

</div>

The possible support of regular expressions for the ‘matches’ AQL comparison operator was discussed in the 2019 Discourse Topic ‘AQL spec review for stabilization, formalization and cleanup’ (AQL spec review for stabili…

---

## [AQL querying on ISM and Careflow Steps](https://discourse.openehr.org/t/aql-querying-on-ism-and-careflow-steps/2650)

<div class="topic-metadata">

**Author:** [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)\
**Replies:** 4\
**Last updated:** [21 June 2025 20:13 UTC](https://discourse.openehr.org/t/aql-querying-on-ism-and-careflow-steps/2650 "2025-06-21T20:13:03Z")

</div>

Hi all, we are currently diving a bit deeper into this topic and I got some questions. To my understanding, an Activity inside an Instruction is referenced by an action entry within the instruction\_details. Now, we wan…

---

## [AQL issue with Same cluster used in multiple archetypes in the same template in version 2.0](https://discourse.openehr.org/t/aql-issue-with-same-cluster-used-in-multiple-archetypes-in-the-same-template-in-version-2-0/6763)

<div class="topic-metadata">

**Author:** [@Sravanthi\_Kovi](https://discourse.openehr.org/u/Sravanthi_Kovi)\
**Replies:** 5\
**Last updated:** [9 May 2025 04:39 UTC](https://discourse.openehr.org/t/aql-issue-with-same-cluster-used-in-multiple-archetypes-in-the-same-template-in-version-2-0/6763 "2025-05-09T04:39:21Z")

</div>

sample\_template.en.v0.t.json (190.3 KB) AQL : { “q”: " SELECT c1/items\[at0031\]/value/value as staging, c1/items\[at0003\]/value/value as T, c1/items\[at0004\]/value/value as M, c1/items\[at0005\]/value/value as N FROM EHR …

---

## [Usage of Aliases in WHERE clause](https://discourse.openehr.org/t/usage-of-aliases-in-where-clause/1291)

<div class="topic-metadata">

**Author:** [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)\
**Replies:** 14\
**Last updated:** [2 December 2024 18:16 UTC](https://discourse.openehr.org/t/usage-of-aliases-in-where-clause/1291 "2024-12-02T18:16:39Z")

</div>

Hi all, I stumbled upon the following expression: select a\_a/data\[at0002\]/events\[at0003\]/data\[at0001\]/items\[at0004\]/value/magnitude as Temperature\_magnitude, e/ehr\_id/value, a\_a/data\[at0002\]/events\[at0003\]/…

---

## [Issue with CONTAINS() string function in AQL](https://discourse.openehr.org/t/issue-with-contains-string-function-in-aql/5744)

<div class="topic-metadata">

**Author:** [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)\
**Replies:** 0\
**Last updated:** [23 September 2024 08:50 UTC](https://discourse.openehr.org/t/issue-with-contains-string-function-in-aql/5744 "2024-09-23T08:50:05Z")

</div>

I did not notice earlier but it looks like there is an issue with AQL ANTLR lexer around the CONTAINS() string function, as it collides with CONTAINS operator. functionCall : terminologyFunction | name=(STRING\_F…

---

## [Questions on AQL CONTAINS formalism](https://discourse.openehr.org/t/questions-on-aql-contains-formalism/5631)

<div class="topic-metadata">

**Author:** [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)\
**Replies:** 7\
**Last updated:** [12 September 2024 14:27 UTC](https://discourse.openehr.org/t/questions-on-aql-contains-formalism/5631 "2024-09-12T14:27:14Z")

</div>

I have some follow-up questions about AQL implementation, on the topic of CONTAINS formalism, which was heavily discussed 2019-2021. A lot of ‘teasers’ and example-based-debates where published here on discourse; it take…

---

## [The challenge of querying different levels of data at the same time](https://discourse.openehr.org/t/the-challenge-of-querying-different-levels-of-data-at-the-same-time/5685)

<div class="topic-metadata">

**Author:** [@linforest](https://discourse.openehr.org/u/linforest)\
**Replies:** 6\
**Last updated:** [10 September 2024 20:02 UTC](https://discourse.openehr.org/t/the-challenge-of-querying-different-levels-of-data-at-the-same-time/5685 "2024-09-10T20:02:40Z")

</div>

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…

---

## [AQL - Querying observations of various types in compositions](https://discourse.openehr.org/t/aql-querying-observations-of-various-types-in-compositions/5645)

<div class="topic-metadata">

**Author:** [@linforest](https://discourse.openehr.org/u/linforest)\
**Replies:** 4\
**Last updated:** [2 September 2024 20:59 UTC](https://discourse.openehr.org/t/aql-querying-observations-of-various-types-in-compositions/5645 "2024-09-02T20:59:47Z")

</div>

When trying to return observations of various types in compositions, the following AQL query was used: SELECT e/ehr\_id/value, c/archetype\_details/template\_id/value, c/uid/value, obs/data\[at0002\]/events\[at0003\]/data…

---

## [Query information stored in a link](https://discourse.openehr.org/t/query-information-stored-in-a-link/5611)

<div class="topic-metadata">

**Author:** [@Cartwright](https://discourse.openehr.org/u/Cartwright)\
**Replies:** 1\
**Last updated:** [23 August 2024 15:05 UTC](https://discourse.openehr.org/t/query-information-stored-in-a-link/5611 "2024-08-23T15:05:37Z")

</div>

Dear all, I want to retrieve the target item stored in a link. Using the following AQL query: SELECT c/links FROM EHR e CONTAINS COMPOSITION c I could output the list of links (containing one link only): \[ \[ …

---

## [AQL for getting a list of deleted compositions](https://discourse.openehr.org/t/aql-for-getting-a-list-of-deleted-compositions/5523)

<div class="topic-metadata">

**Author:** [@Dileep\_V\_S](https://discourse.openehr.org/u/Dileep_V_S)\
**Replies:** 11\
**Last updated:** [5 August 2024 13:26 UTC](https://discourse.openehr.org/t/aql-for-getting-a-list-of-deleted-compositions/5523 "2024-08-05T13:26:27Z")

</div>

Can I use AQL to get a list of deleted compositions? regards

---

## [AQL query using function SUBSTRING](https://discourse.openehr.org/t/aql-query-using-function-substring/5412)

<div class="topic-metadata">

**Author:** [@Lucas](https://discourse.openehr.org/u/Lucas)\
**Replies:** 5\
**Last updated:** [1 July 2024 07:21 UTC](https://discourse.openehr.org/t/aql-query-using-function-substring/5412 "2024-07-01T07:21:34Z")

</div>

My current situation: Based on the specification for the Archetype Query Languange for SUBSTRING I am testing a possibility how to perform a query by using the SUBSTRING of the attribute “name” of the template and compa…

---

## [AQL formalism](https://discourse.openehr.org/t/aql-formalism/5404)

<div class="topic-metadata">

**Author:** [@joostholslag](https://discourse.openehr.org/u/joostholslag)\
**Replies:** 4\
**Last updated:** [25 June 2024 20:20 UTC](https://discourse.openehr.org/t/aql-formalism/5404 "2024-06-25T20:20:17Z")

</div>

I noticed CKM v1.20 now supports AQL queries as an artefact. Afaik there’s no specified formalism for such an artefact. I think we should specify one. Recently it also came up in the resource expression for authorisation…

---

## [Improve AQL to simplifying the querying of terms](https://discourse.openehr.org/t/improve-aql-to-simplifying-the-querying-of-terms/5120)

<div class="topic-metadata">

**Author:** [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)\
**Replies:** 21\
**Last updated:** [17 April 2024 16:19 UTC](https://discourse.openehr.org/t/improve-aql-to-simplifying-the-querying-of-terms/5120 "2024-04-17T16:19:29Z")

</div>

This is a spinoff from How to make mappings easier to query and to document in openEHR and \[EHRbase\] Storing and querying data without an standalone archetype focusing on issue 4 as described below:

---

## [Better AQL : Selecting Data from "any event"](https://discourse.openehr.org/t/better-aql-selecting-data-from-any-event/5001)

<div class="topic-metadata">

**Author:** [@AMAN\_KUMAR\_JHA](https://discourse.openehr.org/u/AMAN_KUMAR_JHA)\
**Replies:** 6\
**Last updated:** [6 March 2024 14:28 UTC](https://discourse.openehr.org/t/better-aql-selecting-data-from-any-event/5001 "2024-03-06T14:28:43Z")

</div>

I have a template with any event as parent event with cardinality 0…\*. I want to select few columns from any\_event:0 as well as few from any\_event:1 in a single query. Is there any way to do this. I am new to OpenEHR an…

---

## [AQL , DATE(TIME) and WHERE](https://discourse.openehr.org/t/aql-date-time-and-where/955)

<div class="topic-metadata">

**Author:** [@bna](https://discourse.openehr.org/u/bna)\
**Replies:** 34\
**Last updated:** [19 September 2023 16:52 UTC](https://discourse.openehr.org/t/aql-date-time-and-where/955 "2023-09-19T16:52:47Z")

</div>

AQL with WHERE , and when you “filter” data on some DATE(TIME) without given a specific timezone. Should the AQL engine (the CDR) assume it to be UTC timezone? I.e. WHERE o/\<path\>/value \> "2020-31-08T12:04:10" Is thi…

---

## [AQL: querying data from several archetypes](https://discourse.openehr.org/t/aql-querying-data-from-several-archetypes/4430)

<div class="topic-metadata">

**Author:** [@tarabonet](https://discourse.openehr.org/u/tarabonet)\
**Replies:** 9\
**Last updated:** [9 September 2023 14:26 UTC](https://discourse.openehr.org/t/aql-querying-data-from-several-archetypes/4430 "2023-09-09T14:26:24Z")

</div>

Hi everyone! In Catalonia we are working to evolve our Shared Electronic Health Record (HC3) to OpenEHR and we have faced a problem that we would like to consult. The way in which we currently collect the clinical vari…

---

## [AQL - the simplest possible question?](https://discourse.openehr.org/t/aql-the-simplest-possible-question/533)

<div class="topic-metadata">

**Author:** [@bna](https://discourse.openehr.org/u/bna)\
**Replies:** 34\
**Last updated:** [7 September 2023 11:24 UTC](https://discourse.openehr.org/t/aql-the-simplest-possible-question/533 "2023-09-07T11:24:36Z")

</div>

Given a CDR with only two compositions and one EHR. Composition 1 (C1) has one OBSERVATIONS. Composition 2 (C2) has two OBSERVATIONS. And you query with the following AQL: SELECT c FROM COMPOSITION c CONTAINS OBSERVA…

---

## [Using aggregate function: count() in where clause](https://discourse.openehr.org/t/using-aggregate-function-count-in-where-clause/4079)

<div class="topic-metadata">

**Author:** [@CzarMich](https://discourse.openehr.org/u/CzarMich)\
**Replies:** 2\
**Last updated:** [11 June 2023 15:29 UTC](https://discourse.openehr.org/t/using-aggregate-function-count-in-where-clause/4079 "2023-06-11T15:29:23Z")

</div>

I would like to find duplicate entries based on a specific field (OrderNumber). I tried out the query below but no success. Will be glad for any guidance. I am using Better Platform. Thank you. SELECT c/feeder\_audit/o…

---

## [Formatting AQL in new topics](https://discourse.openehr.org/t/formatting-aql-in-new-topics/3464)

<div class="topic-metadata">

**Author:** [@siljelb](https://discourse.openehr.org/u/siljelb)\
**Replies:** 7\
**Last updated:** [7 May 2023 15:44 UTC](https://discourse.openehr.org/t/formatting-aql-in-new-topics/3464 "2023-05-07T15:44:37Z")

</div>

Could we add to the description of this category the suggestion to format all posted AQL queries before posting a new topic? This way it’s much easier for people to read and respond to the question. Example: SELECT c F…

---

## [How to use LIKE in AQL?](https://discourse.openehr.org/t/how-to-use-like-in-aql/1147)

<div class="topic-metadata">

**Author:** [@luiz\_Minelli](https://discourse.openehr.org/u/luiz_Minelli)\
**Replies:** 6\
**Last updated:** [28 April 2023 12:51 UTC](https://discourse.openehr.org/t/how-to-use-like-in-aql/1147 "2023-04-28T12:51:05Z")

</div>

hello, I’m trying to use a LIKE in AQL, but it doesn’t work … how do I like to search for any place that has this certain date? How can I do it?

---

## [Querying more than one template (JOIN)](https://discourse.openehr.org/t/querying-more-than-one-template-join/3751)

<div class="topic-metadata">

**Author:** [@CzarMich](https://discourse.openehr.org/u/CzarMich)\
**Replies:** 12\
**Last updated:** [27 March 2023 16:30 UTC](https://discourse.openehr.org/t/querying-more-than-one-template-join/3751 "2023-03-27T16:30:51Z")

</div>

Probably this is an overkill or there is somebody out there who has faced the same issue. I am trying to perform a simple “join” (as per SQL terms) to count patients that are contained in the 3 different templates (dif…

---

## [AQL and ADL syntax highlighting in Discourse](https://discourse.openehr.org/t/aql-and-adl-syntax-highlighting-in-discourse/3526)

<div class="topic-metadata">

**Author:** [@marcusbaw](https://discourse.openehr.org/u/marcusbaw)\
**Replies:** 0\
**Last updated:** [3 February 2023 14:04 UTC](https://discourse.openehr.org/t/aql-and-adl-syntax-highlighting-in-discourse/3526 "2023-02-03T14:04:07Z")

</div>

Continuing the discussion from Formatting AQL in new topics: @ian.mcnicoll @thomas.beale Please feel free to move this topic if Specifications \> AQL isn’t the right place. @siljelb asked if this is possible - as far a…

---

## [AQL fetch issue when Two different templates has same archetype in version 23](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461)

<div class="topic-metadata">

**Author:** [@Mancini](https://discourse.openehr.org/u/Mancini)\
**Replies:** 11\
**Last updated:** [20 January 2023 17:51 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461 "2023-01-20T17:51:34Z")

</div>

Hi Team, We have created two templates with same archetype sign/symptom created using same composition encounter v1, While inserting data we have inserted two data points one is observation, and other is for cluster fo…

---

## [Querying composer's identifiers for where condition](https://discourse.openehr.org/t/querying-composers-identifiers-for-where-condition/3405)

<div class="topic-metadata">

**Author:** [@ardihikaru](https://discourse.openehr.org/u/ardihikaru)\
**Replies:** 3\
**Last updated:** [7 January 2023 10:44 UTC](https://discourse.openehr.org/t/querying-composers-identifiers-for-where-condition/3405 "2023-01-07T10:44:20Z")

</div>

Hi all. Does anyone know how to query a value that’s inside an Array List? In my case, I would like to get the value of id, type, issuer, and assigner. Here is the sniped composer data: What can I achieve so far is…

[Next page](https://discourse.openehr.org/c/specifications/aql/43.md?page=1)
