# FOUND\_ROWS

## Syntax

```sql
FOUND_ROWS()
```

## Description

A [SELECT](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select) statement may include a [LIMIT](https://mariadb.com/docs/server/sql-statements/data-manipulation/selecting-data/select#limit) clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include an [SQL\_CALC\_FOUND\_ROWS](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/optimizer-hints#sql_calc_found_rows) option in the `SELECT` statement, and then invoke `FOUND_ROWS()` afterwards.

You can also use `FOUND_ROWS()` to obtain the number of rows returned by a `SELECT` which does not contain a `LIMIT` clause. In this case you don't need to use the `SQL_CALC_FOUND_ROWS` option. This can be useful for example in a [stored procedure](https://mariadb.com/docs/server/server-usage/stored-routines/stored-procedures).

Also, this function works with some other statements which return a result set, including [SHOW](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/show), [DESC](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/describe) and [HELP](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/help-command). For [DELETE ... RETURNING](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/changing-deleting-data/delete) you should use [ROW\_COUNT()](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/row_count). It also works as a [prepared statement](https://mariadb.com/docs/server/reference/sql-statements/prepared-statements), or after executing a prepared statement.

Statements which don't return any results don't affect `FOUND_ROWS()` - the previous value will still be returned.

**Warning:** When used after a [CALL](https://mariadb.com/docs/server/reference/sql-statements/stored-routine-statements/call) statement, this function returns the number of rows selected by the last query in the procedure, not by the whole procedure.

Statements using the `FOUND_ROWS()` function are not [safe for statement-based replication](https://mariadb.com/docs/server/ha-and-performance/standard-replication/unsafe-statements-for-statement-based-replication).

## Examples

```sql
SHOW ENGINES\G
*************************** 1. row ***************************
      Engine: CSV
     Support: YES
     Comment: Stores tables as CSV files
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 2. row ***************************
      Engine: MRG_MyISAM
     Support: YES
     Comment: Collection of identical MyISAM tables
Transactions: NO
          XA: NO
  Savepoints: NO

...

*************************** 8. row ***************************
      Engine: PERFORMANCE_SCHEMA
     Support: YES
     Comment: Performance Schema
Transactions: NO
          XA: NO
  Savepoints: NO
8 rows in set (0.000 sec)

SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|           8 |
+--------------+
```

```sql
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name WHERE id > 100 LIMIT 10;
...
SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|           23 |
+--------------+
```

## See Also

* [ROW\_COUNT()](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/row_count)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/found_rows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
