开发者

How do I select count() and LIMIT?

开发者 https://www.devze.com 2022-12-22 10:01 出处:网络
SELECT * FROM ...LIMIT 开发者_高级运维5, 10 But what if I want the total rows? I don\'t want to make another query without the limit. I just want this one query to return the total rows if I didn\'t
SELECT * FROM ...LIMIT 开发者_高级运维5, 10

But what if I want the total rows? I don't want to make another query without the limit. I just want this one query to return the total rows if I didn't put the LIMIT in there.


the only way is like this (use 2 queries):

SELECT SQL_CALC_FOUND_ROWS ..... FROM table WHERE ...  LIMIT 5, 10;

and right after run this :

SELECT FOUND_ROWS();

read more :

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

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows


Use

select count (*) from table_name
0

精彩评论

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

关注公众号