# AQL - the simplest possible question?

**URL:** <https://discourse.openehr.org/t/aql-the-simplest-possible-question/533>\
**Category:** AQL\
**Tags:** aql\
**Created:** [27 March 2020 07:14 UTC](https://discourse.openehr.org/t/aql-the-simplest-possible-question/533 "2020-03-27T07:14:17Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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:** [28 March 2020 07:56 UTC](https://discourse.openehr.org/t/aql-the-simplest-possible-question/533/10 "2020-03-28T07:56:30Z")

</div>

I published the example here: [https://github.com/bjornna/openehr-conformance/blob/master/aql/example\_comp\_obs.adoc](https://github.com/bjornna/openehr-conformance/blob/master/aql/example_comp_obs.adoc)

The example illustrates how `contains` has two different semantic meanings.

In the first example it is used as a _filter_ on data. In example 2 it is used as an _inner join_ on data. The interpretation depends on how the client defines the select.

One way to implement the datastructure above might be with a simple database model. Two tables where needed. _COMPOSITION_ and _OBSERVATION_ .

Simple databasemodel for the example

```auto
Table COMPOSITION
|----|
| ID |
|----|
| C1 |
| C2 |
|----|

Table OBSERVATION
|---------|
| ID | CID|
|---------|
| O1 | C1 |
| O2 | C2 |
| O3 | C2 |
|---------|

CID = Reference key to the COMPOSITION

```

SQL equivalent to example 1

`select c.ID from COMPOSITION c inner join OBSERVATION o on o.CID = c.ID`

SQL equivalent to example 2

`select c.ID, o.ID from COMPOSITION c inner join OBSERVATION o on o.CID = c.ID`

---

_[View the full topic](https://discourse.openehr.org/t/aql-the-simplest-possible-question/533)._
