Jump to content


Photo

Need To Limit Count... Lol


  • Please log in to reply
7 replies to this topic

#1 Monkuar

Monkuar

    Advanced Member

  • Members
  • PipPipPip
  • 885 posts

Posted 29 December 2012 - 02:24 AM

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?
I learn more on this site than I did in K-12 Grade...  (Barand Is a MYSQL King) I dont offer help to anyone anymore because I am the the person who needs help....

"Even if I did learn php 100% I wouldn't even be smart enough to use it..." - monkuar

#2 Manixat

Manixat

    Advanced Member

  • Members
  • PipPipPip
  • 166 posts

Posted 29 December 2012 - 06:30 AM

post your error message

Edited by Manixat, 29 December 2012 - 06:41 AM.


#3 trq

trq

    Advanced Member

  • Administrators
  • 31,019 posts
  • LocationSydney, Australia.

Posted 29 December 2012 - 06:34 AM

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.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#4 scootstah

scootstah

    Advanced Member

  • Gurus
  • 2,889 posts
  • LocationUSA

Posted 29 December 2012 - 06:43 AM

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.
while(!$succeed = try());

#5 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 29 December 2012 - 09:32 AM

Use a subquery, set the limit in that, and have the count be in the outer query.

Edited by Christian F., 29 December 2012 - 09:32 AM.

Keeping it simple.

#6 trq

trq

    Advanced Member

  • Administrators
  • 31,019 posts
  • LocationSydney, Australia.

Posted 29 December 2012 - 04:07 PM

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?

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#7 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,373 posts
  • LocationCheshire, UK

Posted 29 December 2012 - 06:00 PM

It could be less than 2500

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#8 trq

trq

    Advanced Member

  • Administrators
  • 31,019 posts
  • LocationSydney, Australia.

Posted 30 December 2012 - 03:54 AM

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;

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com