# Query information stored in a link

**URL:** <https://discourse.openehr.org/t/query-information-stored-in-a-link/5611>\
**Category:** AQL\
**Tags:** rest-apis, aql, links\
**Created:** [23 August 2024 13:05 UTC](https://discourse.openehr.org/t/query-information-stored-in-a-link/5611 "2024-08-23T13:05:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cartwright](https://discourse.openehr.org/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Cartwright](https://discourse.openehr.org/u/Cartwright)\
**Post date:** [23 August 2024 13:05 UTC](https://discourse.openehr.org/t/query-information-stored-in-a-link/5611/1 "2024-08-23T13:05:52Z")

</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):

```auto
  [
    [
      {
        "meaning": {
          "_type": "DV_TEXT",
          "value": "MeaningParent com.example.restservice.zib.compositions.burgerlijkestaatcomposition.BurgerlijkeStaatComposition"
        },
        "target": {
          "value": "ehr://TargetParent"
        },
        "type": {
          "_type": "DV_TEXT",
          "value": "TypeParent alcohol_gebruik"
        }
      }
    ]
]

```

I’ve tried to retrieve the first item of the list using `c/links[0]` with no successes.  
Is it something possible to achieve with AQL?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![ian.mcnicoll](https://discourse.openehr.org/user_avatar/discourse.openehr.org/ian.mcnicoll/32/4430_2.png) [@ian.mcnicoll](https://discourse.openehr.org/u/ian.mcnicoll)\
**Post date:** [23 August 2024 15:05 UTC](https://discourse.openehr.org/t/query-information-stored-in-a-link/5611/2 "2024-08-23T15:05:37Z")

</div>

Array-indexes are not supported AFAIK. Certainly dos not work on Better’s CDR.

You would have to do something like this

```auto
SELECT c/links as clinks
 FROM EHR e 
 CONTAINS COMPOSITION c
 OFFSET 0 LIMIT 1

```

or

```auto
SELECT TOP 1 c/links as clinks
 FROM EHR e 
 CONTAINS COMPOSITION c

```

Though TOP is being deprecated

It’s possibly not a great idea to filter on array position though as my understanding is that the order of each row is essentially indeterminate, and you may not get back what you think of as the ‘first row’
