Is this possible to get total number of rows count with offset limit

江枫思渺然 提交于 2019-12-22 03:32:11

问题


Hey Guyz Is this possible to get total number of rows count with offset limit

Scenario

SELECT * FROM users limit 0,5; 

This Query contain 300 records but the issue is if i call this query with offset the result will be show only 5 record and i don't want to write a Query in twice time. one for paging limit and other for total no of record count...

I don't want this

SELECT * FROM users limit 0,5; // paging 
SELECT count(*) FROM users; // count 

i have to merge this Queries or helps are definitely appreciated


回答1:


You can use SQL_CALC_FOUND_ROWS like this

SELECT SQL_CALC_FOUND_ROWS * FROM users limit 0,5;

It gets the row count before applying any LIMIT clause. It does need another query to fetch the results but that query can simply be

SELECT FOUND_ROWS()

and hence you don't have to repeat your complicated query.



来源:https://stackoverflow.com/questions/10084413/is-this-possible-to-get-total-number-of-rows-count-with-offset-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!