Problem Description
When you limit the number of rows to be returned by a SQL query, usually used in paging, there are two methods to determine the total number of records:
###Method 1
Include the `SQL_CALC_FOUND_ROWS` option in the original `SELECT`, and then get the total number of rows by running `SELECT FOUND_ROWS()`:
SELECT SQL_CALC_FOUND_ROWS * FROM table WHERE id > 100 LIMIT 10;
SELECT FOUND_ROWS();
###Method 2
Run the query normally, and then get the total number of rows by running `SELECT COUNT(*)`
SELECT * FROM table WHERE id > 100 LIMIT 10;
SELECT COUNT(*) FROM table WHERE id > 100;
**Which method is the best / fastest?**
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?