开发者

COUNT with LIMIT in mysql query

i need to get total amount of rows when using LIMIT wi开发者_StackOverflowth my query to avoid twice querying. is it possible?


Use FOUND_ROWS():

For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause

use the statement right after your SELECT query, which needs the CALC_FOUND_ROWS keyword. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜