开发者

calc total number of row vs. select all and then cal the size

I have a big database of users.

i have a query to filter them out and i encode in JSON the results.

i want to have at the same time the total number of the query ("Result found: 507") but i dont want to load them all 507 but just the first 25...

i guess i have to write two queries, one for calc the toal and one to laod t开发者_开发问答he first 25 right? any better solution?

thanks!


select *, count(id) as c FROM table
UNION ALL
select *, 0 as c FROM table
LIMIT 25

something like this gives 26 records, first one being a duplicate but having the total count in field 'c'


i think this gives the right answer

SQL_CALC_FOUND_ROWS and FOUND_ROWS()

via http://www.arraystudio.com/as-workshop/mysql-get-total-number-of-rows-when-using-limit.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜