ID EN
Information Functions

FOUND_ROWS()

MySQL 8.4 🇮🇩 Bahasa Indonesia

Pengubah kueri SQL_CALC_FOUND_ROWS dan fungsi FOUND_ROWS() yang menyertainya tidak digunakan lagi; berharap mereka dihapus di versi MySQL yang akan datang. Jalankan kueri dengan LIMIT, lalu kueri kedua dengan COUNT(*) dan tanpa LIMIT untuk menentukan apakah ada baris tambahan. Misalnya, alih-alih pertanyaan berikut:

Syntax

MYSQL
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name WHERE id > 100 LIMIT 10;
SELECT FOUND_ROWS();

Contoh

Example

Use these queries instead:

MYSQL
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name WHERE id > 100 LIMIT 10;
SELECT FOUND_ROWS();
Example 2

COUNT(*) is subject to certain optimizations. SQL_CALC_FOUND_ROWS causes some optimizations to be disabled.

MYSQL
SELECT * FROM tbl_name WHERE id > 100 LIMIT 10;
SELECT COUNT(*) FROM tbl_name WHERE id > 100;
Example 3

A SELECT statement may include a 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 option in the SELECT statement, and then invoke FOUND_ROWS() afterward:

MYSQL
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10;
SELECT FOUND_ROWS();
Example 4

The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.

MYSQL
SELECT SQL_CALC_FOUND_ROWS * FROM ... ;
SET @rows = FOUND_ROWS();