---
title: Filtering with WHERE
summary: Combine conditions with AND, OR and NOT, compare numbers and strings, match lists, ranges and regular expressions.
order: 20
terms: [bql, attribute]
see-also: [tutorials/bql/your-first-query, tutorials/bql/properties-and-quantities, reference/bql/where]
---

# Filtering with WHERE

The `WHERE` clause is a boolean expression over the features of an object. The previous lesson used one comparison; this one shows how comparisons combine and what they can compare.

## Combining conditions

`AND`, `OR` and `NOT` work as you expect, and parentheses group. `AND` binds tighter than `OR`, so write the parentheses when an `OR` is involved:

```bql {#combine}
GET qid, attribute.Name, attribute.LongName
WHERE type = IFCSPACE AND (attribute.LongName = "keuken" OR attribute.LongName = "badkamer")
```

`NOT` negates the condition after it: `type = IFCDOOR AND NOT attribute.Name CONTAINS "stelkozijn"` gives the doors whose name does not contain that word. Note that `NOT` is the complement, so it also keeps objects that have no name at all.

## Comparing values

Numbers take `=`, `!=`, `<`, `<=`, `>`, `>=`, `IN (…)` and `BETWEEN a AND b` (inclusive on both ends). A numeric literal may carry a unit, `> 2.5 m`, which the next lessons use on quantities. Strings take `=`, `!=` and `IN ("a", "b")`, plus four comparators of their own:

| Comparator | Matches when the value … |
| --- | --- |
| `CONTAINS "x"` | contains `x` anywhere |
| `STARTS_WITH "x"` | begins with `x` |
| `ENDS_WITH "x"` | ends with `x` |
| `MATCHES_REGEX "^D[0-9][LR]$"` | matches the regular expression as a whole |
| `LENGTH > 5` | is longer than 5 characters (any of `= != < <= > >=`) |

String comparisons ignore case. Put `CS` in front of the comparator when case matters: `attribute.Name CS = "D1L"`, `attribute.Name CS STARTS_WITH "D"`. The regular expression is Java syntax and must match the whole value: `MATCHES_REGEX "D[0-9]"` does not match `D1L`, `MATCHES_REGEX "D[0-9].*"` does. All comparators are listed in [[bql:where]].

## Missing values

A feature written without a comparator is a condition of its own and means "has a value": `type = IFCDOOR AND attribute.Description` gives the doors that carry a description — none in the demo model, as it happens. The opposite is `NOT` in front of it: `type = IFCDOOR AND NOT attribute.Description` gives all 205 doors, because none of them has a description.

```warning
Write "has no value" as `NOT <feature>`, not as `<feature> = null`. The grammar accepts `attribute.Description = null`, but on the demo model it matches nothing at all: a comparison needs a value on the left, and an object without the feature never gets that far. Checked on 2026-09-10 against Schependomlaan.
```

The distinction matters with `!=` too: `attribute.Name != "D1L"` only matches objects that *have* a name.

## Your turn

```lesson {#lesson-1}
goal: List the walls whose name starts with "binnen".
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCWALL
hints: |
  - Add a second condition with AND.
  - STARTS_WITH compares the beginning of a string.
solution: |
  GET qid, attribute.Name WHERE type = IFCWALL AND attribute.Name STARTS_WITH "binnen"
accept: |
  - GET qid, attribute.Name WHERE type = IFCWALL AND attribute.Name MATCHES_REGEX "binnen.*"
```

```lesson {#lesson-2}
goal: List the doors named D1L, D1R or D5L.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCDOOR AND attribute.Name = "D1L"
hints: |
  - Three ORs work, but IN takes a list of strings.
  - Strings are double-quoted and separated by commas.
solution: |
  GET qid, attribute.Name WHERE type = IFCDOOR AND attribute.Name IN ("D1L", "D1R", "D5L")
accept: |
  - GET qid, attribute.Name WHERE type = IFCDOOR AND (attribute.Name = "D1L" OR attribute.Name = "D1R" OR attribute.Name = "D5L")
```

```lesson {#lesson-3}
goal: List the spaces whose LongName contains "slaapkamer" (bedroom) or is exactly "woonkamer" (living room), with name and LongName.
show: json
check: values
starter: |
  GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE
hints: |
  - Two conditions on LongName, combined with OR.
  - The OR needs parentheses next to the AND on type.
  - "slaapkamer 1" and "slaapkamer 2" both contain "slaapkamer".
solution: |
  GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND (attribute.LongName CONTAINS "slaapkamer" OR attribute.LongName = "woonkamer")
accept: |
  - GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND (attribute.LongName = "woonkamer" OR attribute.LongName CONTAINS "slaapkamer")
```

The result of that round is shown as JSON rather than as a table: this is exactly what an SDK hands you. Every leaf is an object with the value and its metadata, and a feature an object has no value for is simply absent — a space without a `LongName` has no `LongName` key.

```lesson {#lesson-4}
goal: List the doors whose name is a D, one digit and an L or R, such as D1L or D5R.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCDOOR AND attribute.Name CONTAINS "D"
hints: |
  - CONTAINS finds a D anywhere in the name; the goal is a shape the whole name has to have.
  - STARTS_WITH cannot express "one digit"; a regular expression can.
  - MATCHES_REGEX must match the whole name, so no ^ and $ are needed.
  - [0-9] is one digit, [LR] is one of the two letters.
solution: |
  GET qid, attribute.Name WHERE type = IFCDOOR AND attribute.Name MATCHES_REGEX "D[0-9][LR]"
accept: |
  - GET qid, attribute.Name WHERE type = IFCDOOR AND attribute.Name MATCHES_REGEX "^D[0-9][LR]$"
```

## You can now

- Combine conditions with `AND`, `OR`, `NOT` and parentheses.
- Compare strings with `CONTAINS`, `STARTS_WITH`, `ENDS_WITH` and `MATCHES_REGEX`, case-sensitive when you add `CS`.
- Test a list with `IN` and a range with `BETWEEN`.
- Tell "has a value" from "is null".

Next: [Properties and quantities](properties-and-quantities.md), where the conditions reach beyond the IFC attributes.
