Is there a way in MySQL for COUNT(*) from a table where, if a number is greater than x , it stops counting there? Basically, I just want to know if the number of records returned from the request is greater than a certain number. If it's more than this number, I don't care how many lines there are, if it's less, tell me the score.
I managed to do this as follows:
-- let x be 100 SELECT COUNT(*) FROM ( SELECT `id` FROM `myTable` WHERE myCriteria = 1 LIMIT 100 ) AS temp
... but I was wondering if there is any convenient way to do this?
Thanks for the suggestions, but I would have to more clearly explain the reasons for this issue. He selects from a pair of joined tables, each of which contains tens of millions of records. Executing COUNT(*) using an indexed criterion still takes about 80 seconds, and one without an index takes about 30 minutes or so. This is more of a query optimization than getting the right output.
sql database mysql count query-optimization
nickf
source share