Monkuar Posted December 29, 2012 Share Posted December 29, 2012 Okay, no idea why LIMIT doesn't work on count. I only want to limit the first 2500 rows..... SELECT COUNT(id) as reports FROM users WHERE id != 1 LIMIT 2500 still does not work, any idea? Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/ Share on other sites More sharing options...
Manixat Posted December 29, 2012 Share Posted December 29, 2012 (edited) post your error message Edited December 29, 2012 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1401992 Share on other sites More sharing options...
trq Posted December 29, 2012 Share Posted December 29, 2012 You are kidding right? You want a count of how many records there are in your query but limit it to 2500 ? That would be 2500. Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1401993 Share on other sites More sharing options...
scootstah Posted December 29, 2012 Share Posted December 29, 2012 COUNT() only returns one row, so that's why you can't LIMIT it. You could do a normal SELECT query and then use PHP to count the result set. Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1401995 Share on other sites More sharing options...
Christian F. Posted December 29, 2012 Share Posted December 29, 2012 (edited) Use a subquery, set the limit in that, and have the count be in the outer query. Edited December 29, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1402016 Share on other sites More sharing options...
trq Posted December 29, 2012 Share Posted December 29, 2012 Use a subquery, set the limit in that, and have the count be in the outer query. This will return 2500. The point of my original reply was not that it couldn't be done. It is that it makes NO SENSE to do so. The number the op wants is 2500, why run a database query to get it? Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1402079 Share on other sites More sharing options...
Barand Posted December 29, 2012 Share Posted December 29, 2012 It could be less than 2500 Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1402091 Share on other sites More sharing options...
trq Posted December 30, 2012 Share Posted December 30, 2012 Potentially. Though I get the impression it's not. In that case though, I would use something like: SELECT IF (COUNT(id) > 2500, 2500, COUNT(id)) AS total FROM tbl; Quote Link to comment https://forums.phpfreaks.com/topic/272477-need-to-limit-count-lol/#findComment-1402153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.