---
title: Sub-features and relations
summary: Reading features of related objects — the single-target and multi-target relations, dot and parenthesised forms, nested WHERE/ORDER BY/LIMIT, the all/any/count quantifiers in WHERE, systems, zones, ports, space boundaries and decomposition.
order: 200
terms: [sub-feature]
see-also: [reference/bql/get, reference/bql/where, reference/bql/building-storeys, reference/bql/type-objects, reference/bql/openings-and-fillings]
---

# Sub-features and relations

A [[term:sub-feature|sub-feature]] is a feature of a related object: the name of an object's storey, the type of its children, the area of the windows in its boundaries. A relation name in front of a feature path moves the evaluation to the related object(s).

## Relations {#relations}

Single-target relations point at one object; multi-target relations at a set.

| Relation | Target | GET | WHERE |
|---|---|---|---|
| `project`, `site`, `building`, `buildingStorey`, `space` | The containing spatial element of that class | yes | yes |
| `containedIn` | The immediate spatial container | yes | yes |
| `parent` | The parent in the object tree (containment or decomposition) | yes | yes |
| `decomposes` | The assembly this object is a part of | yes | yes |
| `typeObject` | The object's type definition ([[bql:type-objects]]) | yes | yes |
| `relatedBuildingElement` | From a space boundary, the building element it belongs to | yes | yes |
| `own` | The object itself, without data merged from its type ([[bql:type-objects#own]]) | yes | yes |
| `portConnectedTo`, `portContainedIn` | From a port: the port it connects to; the element that contains it | yes | — |
| `fillsVoid`, `voidsElement` | Opening and filling, single form ([[bql:openings-and-fillings]]) | yes | — |
| `children`, `allChildren` | Direct children; all descendants | yes | `children` |
| `containmentChildren`, `decompositionChildren` | Children by spatial containment only; by decomposition only | yes | — |
| `system`, `zone` | The systems (`IfcSystem`) and zones (`IfcZone`) the object is assigned to | yes | yes |
| `members` | From an `IfcZone`, `IfcSystem` or `IfcGroup`: the objects it groups — the inverse of `zone` and `system` | yes | — |
| `port` | The object's distribution ports | yes | yes |
| `spaceBoundary` | The space boundaries of a space or element | yes | yes |
| `hasOpenings`, `hasFillings`, `fills`, `fillings` | Openings and fillings, multi forms ([[bql:openings-and-fillings]]) | yes | — |

The WHERE column says whether the relation can start a condition path ([[bql:where#paths]]); every relation can be used in `GET`.

## Dot form {#dot}

`<relation>.<feature>` reads one feature of the related object; for a multi-target relation, a list. Relations chain: `spaceBoundary.relatedBuildingElement.attribute.Name`.

```bql {#dot-single}
GET qid, attribute.Name, parent.attribute.Name, typeObject.attribute.Name WHERE type = IFCDOOR
```

```bql {#dot-multi}
GET qid, attribute.Name, system.attribute.Name, port.attribute.Name WHERE type = IFCFLOWSEGMENT
```

## Parenthesised form {#parenthesised}

`<relation>(<feature>, <feature>, ...)` reads several features of the related object(s) as one nested record. A multi-target relation also accepts `WHERE`, `GROUP BY`, `ORDER BY` and `LIMIT` inside the parentheses, applied to the related set per object.

```bql {#paren-single}
GET qid, buildingStorey(attribute.Name, attribute.Elevation) WHERE type = IFCWALL
```

```bql {#paren-multi}
GET attribute.Name, children(qid, niceType, attribute.Name WHERE type IN (IFCDOOR, IFCWINDOW) ORDER BY attribute.Name LIMIT 10)
WHERE type = IFCBUILDINGSTOREY
```

## Aggregates over a relation {#aggregates}

An aggregate in the parentheses summarises the related set per object. A numeric aggregate gives a number, usable in `GET` and as a `WHERE` operand ([[bql:where#relation-aggregates]]). `COUNT(children)` counts direct children ([[bql:get#special]]).

```bql {#relation-aggregate}
GET qid, attribute.Name, spaceBoundary(SUM(quantity.*.Area) WHERE type = IFCWINDOW) AS WindowArea, COUNT(children) AS Children WHERE type = IFCSPACE
```

`COUNT`, `FIRST` and `COLLECT` work over a relation too: `COUNT(qid)` counts the related objects that pass the `WHERE`, `FIRST(feature)` is the feature of the first related object that has it, `COLLECT(feature)` the list of them (`COLLECT(DISTINCT feature)`: every different one once). `ORDER BY` and `LIMIT` shape the related set before it is aggregated, so `FIRST` with `ORDER BY` is the arg-min (or, with `DESC`, the arg-max), and `SUM` with `ORDER BY … DESC LIMIT 3` the sum of the three largest. `GROUP BY` does not combine with aggregates. In the record each value sits under the relation's name and the aggregate's text (`"children": {"COUNT(qid)": …}`), also with an alias (`children(COUNT(qid) AS Spaces WHERE …)`), which names the column in the answer's columns ([[bql:get#nested]], [[bql:get#alias]]).

```bql {#relation-count-first}
GET attribute.Name, children(COUNT(qid) WHERE type = IFCSPACE) AS Spaces, children(FIRST(attribute.Name) WHERE type = IFCSPACE ORDER BY calculated.quantity.floorArea) AS SmallestSpace WHERE type = IFCBUILDINGSTOREY
```

```bql {#relation-members}
GET attribute.Name, members(COUNT(qid) WHERE type = IFCSPACE) AS Spaces WHERE type = IFCZONE
```

A single aggregate over a relation is what a [[page:reference/bfl#relations|virtual feature]] uses to give an object a value that comes from other objects.

## Quantifiers in WHERE {#quantifiers}

A multi-target relation in a condition needs a quantifier: `.any(<condition>)` (at least one related object matches), `.all(<condition>)` (every one does), or `.count(<condition>) <comparator> <n>`.

```bql {#quantifier-any}
GET qid, attribute.Name WHERE type = IFCSPACE AND spaceBoundary.any(relatedBuildingElement.type = IFCWINDOW)
```

```bql {#quantifier-all}
GET qid, attribute.Name WHERE type = IFCBUILDINGSTOREY AND children.all(calculated.geometry.hasGeometry)
```

```bql {#quantifier-count}
GET qid, attribute.Name WHERE type = IFCSYSTEM AND children.count(type = IFCFLOWTERMINAL) > 10
```

A single-target relation takes the condition directly: `buildingStorey.attribute.Name = "Level 1"`, `typeObject.attribute.Name CONTAINS "Double"`, `decomposes.type = IFCCURTAINWALL`.

## children {#children}

`children` are the objects one level below in the tree: spatially contained elements for a storey or space, parts for an assembly. `allChildren` descends the whole subtree; `containmentChildren` and `decompositionChildren` pick one of the two relationship kinds.

```bql {#children}
GET attribute.Name, COUNT(children) AS Direct, allChildren(qid, niceType) AS Everything WHERE type = IFCBUILDINGSTOREY
```

## Systems, zones, ports and space boundaries {#systems}

`system` and `zone` follow the group assignments of an object; `port` follows to its `IfcDistributionPort`s and from a port `portConnectedTo` reaches the connected port and `portContainedIn` the element that owns it; `spaceBoundary` returns the `IfcRelSpaceBoundary` objects of a space (or of a boundary element), and from a boundary `relatedBuildingElement` and `space` reach the two sides.

```bql {#ports}
GET qid, port(qid, attribute.FlowDirection, portConnectedTo.portContainedIn.attribute.Name) WHERE type = IFCFLOWFITTING
```

```bql {#system-group}
GET system.attribute.Name, COLLECT(attribute.Name) GROUP BY system.attribute.Name
```

## decomposition {#decomposition}

The `decomposition` feature returns the object's decomposition tree as nested records of `qid`, `niceType` and `Name`, without spelling out each level.

```bql {#decomposition}
GET qid, attribute.Name, decomposition WHERE type = IFCCURTAINWALL
```

## Used in {#used-in}

- [[page:tutorials/bql/relations]] — storeys, types, materials, children.
