---
title: WHERE
summary: The selection — boolean expressions over features, the numeric and string comparators, tolerances, has-value tests, relation paths with all/any/count, and relation aggregates.
order: 30
terms: [qid]
see-also: [reference/bql/get, reference/bql/types, reference/bql/using, reference/bql/spatial-and-advanced]
---

# WHERE

`WHERE` selects the objects a query returns. Its argument is a boolean expression over the object's features. The same expression language is used, without the `WHERE` keyword, as a bare query, in the `if` and `select` conditions of [[page:reference/bvl|BVL]] and [[page:reference/bcl|BCL]], in the `WHERE` of [[page:reference/bul|BUL]], and inside nested relation queries.

## Syntax {#syntax}

```text {#where-syntax}
GET <features> WHERE <condition>
<condition>                       // without GET: a bare selection
```

`WHERE` needs a `GET` in front of it. A query that only selects is written as the condition alone.

```bql {#where-basic}
GET qid, attribute.Name WHERE type = IFCWALL AND property.Pset_WallCommon.IsExternal = true
```

```bql {#where-bare}
type = IFCWALL AND property.Pset_WallCommon.IsExternal = true
```

## Conditions {#conditions}

A condition is one of:

| Form | Meaning |
|---|---|
| `<feature> <comparator> <value>` | Compare a feature's value ([comparisons](#comparisons), [string comparators](#strings)). |
| `<feature>` | The object has a value for the feature ([has-value](#has-value)). |
| `type …`, `suggestedType …` | Class tests with inheritance ([[bql:types]]). |
| `qid …` | Identity tests ([qid](#qid)). |
| `<relation>.<condition>`, `<relation>.any(…)` | Conditions on related objects ([paths](#paths)). |
| `<relation>(<aggregate> WHERE …) <comparator> <value>` | Aggregates over related objects ([relation aggregates](#relation-aggregates)). |
| `model.<condition>` | Conditions on the model ([[bql:model#conditions]]). |
| `ALL` | Every object. |
| `CLASHES_WITH(…)`, `geometry:…`, `sem:…`, `PART_OF(…)`, `nav:…`, `TEXT_MATCHES(…)`, `geoReference …` | Spatial, semantic and text predicates ([[bql:spatial-and-advanced]]). |

## Logic {#logic}

Conditions combine with `AND`, `OR` and `NOT`; `NOT` binds tightest, then `AND`, then `OR`. Parentheses group.

```bql {#where-logic}
GET qid WHERE (type = IFCWALL OR type = IFCSLAB) AND NOT (property.Pset_WallCommon.IsExternal = true)
```

`NOT` also has dedicated forms: `type NOT IN (...)`, `qid NOT IN (...)`, `attribute.Name NOT IN ("a", "b")`.

## Comparisons {#comparisons}

| Comparator | Right-hand side | Example |
|---|---|---|
| `=` `!=` | A number (with optional unit), string, boolean, `null`, a feature or an arithmetic expression, or a parameter | `quantity.Qto_DoorBaseQuantities.Width = 0.9 m` |
| `<` `<=` `>` `>=` | A number with optional unit, a feature, an expression, or a parameter | `aabb.height > 3 m` |
| `IN (…)` `NOT IN (…)` | A list of numbers, booleans or strings | `attribute.Name IN ("Wall-1", "Wall-2")` |
| `IN $p` `NOT IN $p` | A parameter bound to an array | `property.*.FireRating IN $ratings` |
| `BETWEEN a AND b`, `BETWEEN (a, b)` | Two numbers with optional units, both ends inclusive; or `BETWEEN $range` | `aabb.height BETWEEN 2.4 m AND 3 m` |

Both sides of a numeric comparison take arithmetic (`+ - * /`, `ABS(...)`, parentheses) with automatic unit handling, so two features can be compared with each other. A left side that starts with `(` is fine: `(a + b) > c`.

```bql {#where-arithmetic}
GET qid WHERE type = IFCWALL AND quantity.Qto_WallBaseQuantities.NetVolume > calculated.quantity.volume * 1.1
```

```bql {#where-between}
GET qid, aabb.height WHERE type = IFCDOOR AND aabb.height BETWEEN 2.0 m AND 2.4 m
```

A `=` or `!=` on a decimal number is an exact floating-point comparison and easily misses; the validator warns and suggests `BETWEEN` or a tolerance.

## Tolerances: WITHIN {#within}

`WITHIN` attaches a tolerance to `=` and `!=` on numbers: `a = b WITHIN 5 %` is relative to the right-hand side (|a − b| ≤ 5 % of |b|), `a = b WITHIN 5 mm` is absolute and must match the dimension of the operands, and `a != b WITHIN …` holds when the deviation exceeds the tolerance. A bare number is a tolerance in the operands' own dimension, only meaningful when they are unitless.

```bql {#where-within}
GET qid, quantity.Qto_WallBaseQuantities.NetVolume, calculated.quantity.volume
WHERE type = IFCWALL AND quantity.Qto_WallBaseQuantities.NetVolume != calculated.quantity.volume WITHIN 2 %
```

## String comparators {#strings}

String comparisons are case-insensitive; prefix the comparator with `CS` for a case-sensitive test.

| Comparator | Meaning | Example |
|---|---|---|
| `=` `!=` | Equal, not equal (case-insensitive) | `attribute.Name = "Level 1"` |
| `CS =` `CS !=` | Case-sensitive equal, not equal | `attribute.Name CS = "Level 1"` |
| `IN ("a", "b")`, `CS IN`, `NOT IN`, `CS NOT IN` | Membership | `layer.name IN ("A-WALL", "A-DOOR")` |
| `CONTAINS`, `CS CONTAINS` | Substring | `attribute.Name CONTAINS "wall"` |
| `STARTS_WITH`, `CS STARTS_WITH` | Prefix | `attribute.Name STARTS_WITH "Basic"` |
| `ENDS_WITH`, `CS ENDS_WITH` | Suffix | `attribute.Name ENDS_WITH "01"` |
| `MATCHES_REGEX`, `CS MATCHES_REGEX` | Regular expression over the whole value | `property.*.Nlsfb MATCHES_REGEX "^[0-9][0-9][.][0-9][0-9]$"` |
| `MATCHES "text" [FUZZY [n]]` | Analysed full-text match through the text index; `FUZZY` allows up to `n` edits (1 or 2). Needs text indexing on the instance. | `attribute.Name MATCHES "brandwerend" FUZZY 1` |
| `LENGTH <op> n` | Length of the string, with `=`, `!=`, `<`, `<=`, `>`, `>=` | `attribute.Name LENGTH > 20` |

The right-hand string of `CONTAINS`, `STARTS_WITH`, `ENDS_WITH`, `MATCHES_REGEX`, `MATCHES`, `CS =` and `CS !=` may be a parameter (`CONTAINS $text`). An invalid regular expression is reported at validation and fails the query at runtime.

```bql {#where-strings}
GET qid, attribute.Name WHERE type = IFCSPACE AND attribute.LongName CONTAINS "kitchen" AND attribute.Name LENGTH <= 8
```

## Booleans and null {#booleans}

Boolean properties compare with `true` and `false`; `= null` selects objects that have no value for the feature, `!= null` those that have one.

```bql {#where-null}
GET qid, attribute.Name WHERE type = IFCDOOR AND property.Pset_DoorCommon.FireRating = null
```

## Has-value {#has-value}

A feature on its own, without a comparator, is true when the object has a value for it. `property.*.FireRating` selects every object with a FireRating in any property set; the negation `NOT property.*.FireRating` selects the rest.

```bql {#where-has-value}
GET qid, property.*.FireRating WHERE type = IFCDOOR AND property.*.FireRating
```

A property path needs a member: `property.Pset_WallCommon` alone is a syntax error. To test whether a set exists, use the [[bql:meta|meta feature]] in `GET` and group on it; `.meta` features cannot be filtered on.

## Types {#type}

`type` tests the IFC class including subclasses; `NI` disables inheritance. The forms are `type = IFCWALL`, `type != IFCWALL`, `type IN (IFCWALL, IFCDOOR)`, `type NOT IN (...)`, `type IN $types`, and `type NI = IFCWALL`. `suggestedType` takes the same forms. Class names are upper case; an unknown name is a validation warning and a runtime error ([[error:BimWorksQueryError.UNKNOWN_TYPE]]). Details on [[bql:types]].

## Qids {#qid}

`qid = "<vid>-<oid>"`, `qid IN ("…", "…")`, `qid NOT IN (...)` and `qid IN $selection` select by identity. A qid literal is the version UUID, a dash and the oid; it may be written bare or quoted, and a version with several oids is written `<uuid>[oid, oid]`.

```bql {#where-qid}
GET qid, attribute.Name WHERE qid IN ("797e993c-a87f-4aa7-9587-c59d30ec5c4e-1316", "797e993c-a87f-4aa7-9587-c59d30ec5c4e-1420")
```

## Paths to related objects {#paths}

A relation name followed by a dot applies the rest of the condition to the related object(s). Single-target relations: `project`, `site`, `building`, `buildingStorey`, `space`, `containedIn`, `parent`, `decomposes`, `typeObject`, `relatedBuildingElement`, `own`. Multi-target relations: `children`, `system`, `zone`, `port`, `spaceBoundary`; these take a quantifier: `.all(<condition>)`, `.any(<condition>)` or `.count(<condition>) <comparator> <n>`. Followed by a dot, a multi-target relation compares like `.any`: `zone.attribute.Name = "Lab"` holds when one of the object's zones is named Lab. `zone.attribute.Name = null` holds when none of them has a name or the object is in no zone, the same as `NOT zone.attribute.Name`. Paths chain: `spaceBoundary.relatedBuildingElement.type = IFCWINDOW`.

```bql {#where-path-single}
GET qid, attribute.Name WHERE type = IFCDOOR AND buildingStorey.attribute.Name = "Level 1"
```

```bql {#where-path-multi}
GET qid, attribute.Name WHERE type = IFCSPACE AND children.count(type = IFCFURNISHINGELEMENT) >= 3
```

The relations and what they traverse are on [[bql:sub-features]]; the storey and type-object shortcuts have their own pages ([[bql:building-storeys]], [[bql:type-objects]]).

## Relation aggregates {#relation-aggregates}

A multi-target relation followed by one numeric aggregate in parentheses is a number per object and can be compared like any feature: `spaceBoundary(SUM(quantity.*.Area) WHERE type = IFCWINDOW)`. The aggregate's argument is evaluated on each related object; the optional `WHERE` filters the related set. `SUM` over an empty set is 0; the other aggregates have no value then. The same form is a `GET` item ([[bql:get#nested]]).

```bql {#where-relation-aggregate}
GET qid, attribute.Name
WHERE type = IFCSPACE AND calculated.quantity.floorArea * 0.1 > spaceBoundary(SUM(quantity.*.Area) WHERE type = IFCWINDOW)
```

`COUNT(<condition>)` is also a `WHERE` operand: the number of objects in the queried models that match the condition.

## Model conditions {#model}

`model.ifcVersion = IFC4`, `model.discipline IN (ARCHITECTURAL, STRUCTURAL)` and `model.count(<condition>) > n` select objects by a property of the model they belong to; see [[bql:model#conditions]].

## Parameters {#parameters}

`$name` stands for a value supplied at run time and can replace a literal in nearly every position: `= $x`, `> $min`, `IN $values`, `BETWEEN $lo AND $hi`, `BETWEEN $range`, `CONTAINS $text`, `type IN $types`, `qid IN $selection`, and as the argument of the spatial functions. Binding is on [[bql:using#parameters]].

## Validation notes {#validation}

- `WHERE` without `GET` is a syntax error; a bare condition is the intended form.
- Unknown IFC class names and unknown attribute names are reported with a did-you-mean; the query fails at run time.
- `BETWEEN` with the lower bound above the upper bound matches nothing.
- `.meta` features are selectable, not filterable.
- A feature that is neither aggregated nor a group key in a grouped query returns the value of an arbitrary member of the group.

## Used in {#used-in}

- [[page:tutorials/bql/filtering-with-where]] — comparators, strings, logic.
- [[page:tutorials/bql/relations]] — paths and quantifiers.
- [[page:how-to/query/count-results]] — the count of a selection without fetching it.
- [[page:how-to/query/use-query-parameters]] — `$name` in a stored query.
