---
title: "Count Query Results"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results"
version: "6.2"
language: "php"
---

# Count Query Results

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - The following options are available to **count query results**:
>
>   - [`Count`](#count)
>   - [Get number of results from query stats](#get-count-from-query-stats)

## `Count`

Count query results using the `Count` method.

### documentQuery

```php
/** @var int $numberOfOrders */
$numberOfOrders = $session->advanced()
  ->documentQuery(Order::class)
  ->whereEquals("ship_to.country", "UK")
   // Calling 'Count' from Raven.Client.Documents.Session
  ->Count();

// The query returns the NUMBER of orders shipped to UK (int)
```

### RQL

```sql
from "Orders"
where ShipTo.Country == "UK" limit 0, 0

// The RQL generated will trigger query execution
// however, no documents are returned (limit is set 0)
```

## Get count from query stats

When executing a query, you can retrieve the query statistics that include the total number of results.  
Learn more in [Get Query Statistics](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-get-query-statistics.php.md).

## See also

- [Query overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.php.md)
- [What is a Document Query](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.php.md)
- [Filter by Field Presence](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.php.md)
- [Get Query Statistics](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-get-query-statistics.php.md)
- [Filtering](https://docs.ravendb.net/6.2/indexes/querying/filtering.php.md)
- [RQL - Raven Query Language](https://docs.ravendb.net/6.2/client-api/session/querying/what-is-rql.md)
