Reputation: 359
I know how to use SQL_CALC_FOUND_ROWS
with Limit
to return total number of rows and results for pagination.
But my question is...
What if (for performance purpose) I want to show if total rows exceeds 1,000 I just want to return 1,000 (even if there are more records)?
SELECT Count(id) FROM table WHERE 1
I Google'd a lot but couldn't find this. I thought of this thinking this may improve Fulltext search speed for example.
thanks in advance.
Upvotes: 2
Views: 2450
Reputation: 21
Im pretty sure that mysql has its own counter for the rows built in, when a record gets inputed the marker goes up a notch, what you can do is something like this :
$query = "SELECT * FROM table WHERE maxrows = '1'";
Then have one thousand rows that get the value of one in a maxrows
cell, value of two for another one thousand rows and so on
Upvotes: 1
Reputation: 39690
SELECT LEAST(Count(id),1000) FROM table WHERE 1
Documentation on the LEAST function can be found here: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_least
Upvotes: 1
Reputation: 9562
In many cases it can be faster, but you should test it:
SELECT count(*) FROM ( SELECT 1 FROM t LIMIT 1000 ) a
Upvotes: 4