views:

51

answers:

2
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.

+4  A: 

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

Haim Evgi
A: 
Use

select count (*) from table_name 
pavun_cool