![]() |
![]() |
![]() |
|||||||||||
| Nested Queries < TMQL Introduction < < Home | |||||||||||||
|
Nested QueriesNesting of query expressions is quite natural and could potentially be used in quite a few places. To demonstrate how much the language can be stretched, here an slightly obstruse example to use nesting within a SELECT clause. To lists all groups and their members in the map, the SELECT clause may contain a whole subquery:
select $group / name,
" members are: " + fn:string-join (
fn:tuple ({
select $person / name
where
is-part-of (member: $person, whole: $group)
}), ",")
where $group isa group
The query is actually initiated by finding first all instances of the concept
group. For each of them, the expressions in the SELECT clause are
evaluated. The first column there is always a string containing one group name. The second
column is also a string, but one that is concatenated from a constant string and the result of
a nested query expression.
For a given group we will there find all members and extract their name(s). In any case, the subquery will return a table with a single column, that with the names. To convert this into a list of things, we use the function tmql:tuple; only then we can concatenate the individual strings with commas separated using fn:string-join. |
||||||||||||