>X-Sieve: CMU Sieve 2.1 >X-Mail-from: [EMAIL PROTECTED] >From: "Ryan Fox" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]>, "mos" <[EMAIL PROTECTED]> >Subject: Re: How to Count(*) with LIMIT >Date: Thu, 2 May 2002 08:42:28 -0400 >X-Mailer: Microsoft Outlook Express 6.00.2600.0000 > >----- Original Message ----- >From: "mos" <[EMAIL PROTECTED]> > > > I have a Where clause like: > > select count(*) from table where .... LIMIT 100 > > > > Unfortunately the Count(*) ignores the LIMIT clause entirely. Why? > >You could use least().
That would give the correct result, but it would still physically count all the rows in the table which takes too long. This code will execute every time a web page opens that has a grid. Some of the grid pages are quite large, > 1 million rows. The person who designed the web page originally didn't think that would matter much. I keep telling him you can't count 1 million rows every time a web page opens. The site would probably support around 5 people.<g> I will go with the "mysql_num_rows" which shouldn't add any additional CPU or I/O. It seems like a perfect solution once I move some code around. Thanks. Mike >mysql> select least(count(*),30) from ct; >+--------------------+ >| least(count(*),30) | >+--------------------+ >| 30 | >+--------------------+ >1 row in set (0.00 sec) > >mysql> select count(*) from ct; >+----------+ >| count(*) | >+----------+ >| 43 | >+----------+ >1 row in set (0.00 sec) > >Cheers, > >Ryan Fox, Geek email: [EMAIL PROTECTED] >BackWatcher, Inc. web: http://backwatcher.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php