---
title: Count results
summary: Get the number of objects a query matches without fetching them, with a count call or with a COUNT aggregate.
order: 20
languages: [javascript, java, csharp, php]
terms: [qid, version]
see-also: [how-to/query/run-a-bql-query, how-to/query/use-query-parameters, reference/bql]
---

# Count results

For a page that shows "1,204 walls" before it loads them, for paging, or for a check that only needs a number. Counting runs the same query as [[page:how-to/query/run-a-bql-query]] but transfers one integer instead of every record.

## Before you start

- A login with the `query:run` scope and the version UUIDs ([[page:how-to/query/run-a-bql-query]]).

## 1. Ask for the count

The JavaScript and Java SDKs have a dedicated call, `queryCount`; it takes the query and the models like `query` and returns the count. Over HTTP, [[openapi:Query]] counts with `"format": "count"` and answers `{"count": …}`.

```code-group {#count}
```javascript
const walls = await client.bim.queryCount([BIM_WORKS_FIRST_MODEL], "GET qid WHERE type = IFCWALL");
console.log(walls);   // a number
```
```java
long walls = client.bim.queryCount("GET qid WHERE type = IFCWALL", Set.of(UUID.fromString(BIM_WORKS_FIRST_MODEL)));
```
```

```try-it
operation: Query
method: POST
path: /openapi/ifc/Query
body: |
  {
    "models": [{"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL}],
    "query": "GET qid WHERE type = IFCWALL",
    "format": "count"
  }
```

`queryCount` is on [[js:@bimworks/jssdk/Bim|Bim]] and [[java:nl.bimbase.bimworks.client.apis.BimApi|BimApi]]. It and the `count` format accept the same `parameters` as `query` ([[page:how-to/query/use-query-parameters]]) and count the objects a `GET` query would return; for a `GROUP BY` query they count the groups.

## 2. Or count in the query

Where no count call is available (the .NET SDK, the PHP client), ask BQL for the count: `COUNT(qid)` without a `GROUP BY` yields one record, with the count under the key `COUNT` as `{"name": "COUNT", "value": 13, "unit": "UNITLESS", "type": "int"}`. This is a normal query, so it works everywhere [[page:how-to/query/run-a-bql-query]] works.

```code-group {#aggregate} classic
```csharp
JsonElement result = client.Bim.Query(Guid.Parse(BIM_WORKS_FIRST_MODEL), "GET COUNT(qid) WHERE type = IFCWALL");
int walls = result[0].GetProperty("COUNT").GetProperty("value").GetInt32();
```
```

```sdk-example
operation: Query
body: |
  {
    "models": [{"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL}],
    "query": "GET COUNT(qid) WHERE type = IFCWALL"
  }
```

```try-it
operation: Query
method: POST
path: /openapi/ifc/Query
body: |
  {
    "models": [{"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL}],
    "query": "GET COUNT(qid) WHERE type = IFCWALL"
  }
```

Combined with `GROUP BY` the same aggregate gives a count per group, `GET type, COUNT(qid) GROUP BY type` being the classic inventory of a model. `AS` names the column, `GET COUNT(qid) AS walls`: the count stays under `COUNT` in the record, and the answer's [[page:reference/bql/output#columns|columns]] say that `walls` is there.

## Check

`queryCount` of `GET qid WHERE type = IFCWALL`, the `COUNT(qid)` record of the same condition, and the length of the array `query` returns for it are the same number.
