[英]COUNT with LIMIT in mysql query
i need to get total amount of rows when using LIMIT with my query to avoid twice querying. 在我的查询中使用LIMIT时,我需要获得总行数,以避免两次查询。 is it possible?
可能吗?
Use FOUND_ROWS()
: 使用
FOUND_ROWS()
:
For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause
对于带有LIMIT子句的SELECT,返回的行数没有LIMIT子句
use the statement right after your SELECT query, which needs the CALC_FOUND_ROWS
keyword. 在SELECT查询之后立即使用该语句,该查询需要
CALC_FOUND_ROWS
关键字。 Example from the manual: 手册中的示例:
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10;
Note that this puts additional strain on the database, because it has to find out the size of the full result set every time. 请注意,这会给数据库带来额外的压力,因为它必须每次都找出完整结果集的大小。 Use
SQL_CALC_FOUND_ROWS
only when you need it. 仅在需要时使用
SQL_CALC_FOUND_ROWS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.