我有一个包含 LIMIT 子句的查询,该子句一次返回 10 个结果,总共 100 个结果。我还想要计算结果总数(即 100)。我是否必须在没有 LIMIT 子句的情况下进行第二次查询,然后计算返回的行数?我不想这样做,因为查询非常昂贵。
最佳答案
select sql_calc_found_rows * from table .... limit x;
select found_rows();
看看说明书
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
说的是:
If you are using SELECT SQL_CALC_FOUND_ROWS, MySQL must calculate how many rows are in the full result set. However, this is faster than running the query again without LIMIT, because the result set need not be sent to the client.
关于php - mySQL/Codeigniter 中返回的行数(不受 LIMIT 子句影响),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5954772/