开发者

How to calculate number rows in SQL query limited result set?

开发者 https://www.devze.com 2023-03-08 13:40 出处:网络
I want to fetch only 20 rows from a database table using one condition for example : select * from orders where price > 10000 limit 0,20

I want to fetch only 20 rows from a database table using one condition for example :

select * from orders where price > 10000 limit 0,20

Above query w开发者_运维技巧ill fetch only 20 rows. Is there any way i can get how many rows it can fetch with same condition in WHERE clause when limit 0,20 is not used?. I have to do it in one single query.

Please guide me.

Thanks..


To quote the MySQL docs:

A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward.


This? select count(*) from orders where price > 10000

0

精彩评论

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