# 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" %}
