---
title: Your first query
summary: Select objects by IFC type with GET and WHERE, read their attributes, and limit the result.
order: 10
terms: [bql, qid, attribute, demo-model]
see-also: [tutorials/bql/filtering-with-where, reference/bql/get, reference/bql/types]
---

# Your first query

A BQL statement has two halves. `GET` lists the features you want in the result; `WHERE` says which objects to take them from. Run this against Schependomlaan:

```bql {#first-get}
GET qid, type, attribute.Name WHERE type = IFCDOOR
```

You get one row per door. `qid` is the object's identifier in BIM.works (the [[term:qid]], a version UUID and an object id joined by a hyphen), `type` is its IFC class, and `attribute.Name` is the value of the IFC `Name` attribute. Every IFC attribute is reachable the same way: `attribute.GlobalId`, `attribute.Description`, `attribute.LongName` on spaces, `attribute.Elevation` on storeys. Attribute names are case-sensitive and spelled as in the IFC schema; the editor warns when it does not know one. The full list of what `GET` accepts is in [[bql:get]], attributes in [[bql:attributes]].

## Types include their subtypes

`type = IFCWALL` matches 934 objects in the demo model, although only 652 of them are literally `IfcWall`: the other 282 are `IfcWallStandardCase`, a subtype. Type matching follows the IFC inheritance tree, so `type = IFCBUILDINGELEMENT` matches every wall, slab, door, window and beam at once, and `type = IFCPRODUCT` matches everything with a place in the building. When you mean the exact class and nothing below it, add `NI` (no inheritance):

```bql {#no-inheritance}
GET qid, attribute.Name WHERE type NI = IFCWALL
```

Two more spellings of the same idea are `type IN (IFCDOOR, IFCWINDOW)` and `type != IFCSPACE`; see [[bql:types]]. `niceType` is the class name written the way people write it (`IfcWallStandardCase` instead of `IFCWALLSTANDARDCASE`), handy for output.

## What if there is no WHERE?

Leave the `WHERE` out and you get every object of every model queried, which is rarely what you want but sometimes exactly right (`GET qid, type` is the quickest inventory of a model). The reverse also exists: a query that is only a condition, `type = IFCSPACE`, returns the matching objects with their `qid`. The viewer uses that form to resolve selections; in this course we always write `GET`, so the result shape is explicit. `WHERE` on its own, without `GET`, is a syntax error.

## Keeping the result small

`LIMIT` cuts the result to the first *n* rows, `OFFSET` skips rows before that. Without an `ORDER BY` (a later lesson) the order is the model's own order, which is stable for one version but carries no meaning.

```bql {#limit}
GET qid, attribute.Name WHERE type = IFCWINDOW LIMIT 10
```

## Your turn

Four rounds. Edit the starter query until the result is what the goal asks for, then press Run.

```lesson {#lesson-1}
goal: List every space in the model with its name.
show: table
check: values
starter: |
  GET qid
hints: |
  - Spaces are IfcSpace objects; IFC class names are uppercase in BQL.
  - The name is the IFC attribute Name: attribute.Name.
  - A GET list is separated by commas, and the condition follows in WHERE.
solution: |
  GET qid, attribute.Name WHERE type = IFCSPACE
accept: |
  - GET attribute.Name, qid WHERE type = IFCSPACE
  - GET qid, attribute.Name AS Name WHERE type = IFCSPACE
```

```lesson {#lesson-2}
goal: List every door with its name and its IFC class — the `type` feature itself, not `niceType`.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCSPACE
hints: |
  - Only the type in the WHERE has to change.
  - The class of an object is the feature named type; it can be selected like any other feature.
solution: |
  GET qid, type, attribute.Name WHERE type = IFCDOOR
accept: |
  - GET qid, attribute.Name, type WHERE type = IFCDOOR
```

```lesson {#lesson-3}
goal: List the walls that are exactly IfcWall (not IfcWallStandardCase), with their readable class name and their name.
show: table
check: values
starter: |
  GET qid, attribute.Name WHERE type = IFCWALL
hints: |
  - type = IFCWALL also matches the subtype IfcWallStandardCase.
  - NI after type switches inheritance off.
  - niceType is the readable class name.
solution: |
  GET qid, niceType, attribute.Name WHERE type NI = IFCWALL
accept: |
  - GET qid, attribute.Name, niceType WHERE type NI = IFCWALL
```

```lesson {#lesson-4}
goal: List the GlobalId and the name of at most ten windows.
show: table
check: values
require: \bLIMIT\b
require-message: the result has to be capped with LIMIT, not by a condition that happens to leave ten rows
starter: |
  GET qid, attribute.Name WHERE type = IFCWINDOW
hints: |
  - GlobalId is an IFC attribute like Name.
  - LIMIT goes at the end of the statement.
solution: |
  GET qid, attribute.GlobalId, attribute.Name WHERE type = IFCWINDOW LIMIT 10
accept: |
  - GET qid, attribute.GlobalId, attribute.Name WHERE type = IFCWINDOW LIMIT 10 OFFSET 0
```

## You can now

- Write a `GET … WHERE …` statement and read the rows it returns.
- Select objects by IFC class, with or without their subtypes.
- Read any IFC attribute of the selected objects.
- Cap a result with `LIMIT`.

Next: [Filtering with WHERE](filtering-with-where.md), where the condition becomes more than one type.
