Would that help at all - since the COUNT(*) would execute fully and then
MAX would limit it? (or is the order of operations different than that?)

-M

-----Original Message-----
From: Yves Goergen [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 22, 2003 10:26 AM
To: Mojtaba Faridzad; [EMAIL PROTECTED]
Subject: Re: how to limit COUNT(*)


a LIMIT will not work in any case with COUNT since you will always get
exactly one row. and what shall a LIMIT 10000 on 1 row do here?

but you can try the MAX function here: (i guess it exists :)

SELECT MAX(COUNT(*), 10001) as numfound FROM mytable WHERE mycond;

-yves


-----Ursprüngliche Nachricht----- 
Von: "Mojtaba Faridzad" <[EMAIL PROTECTED]>
An: <[EMAIL PROTECTED]>
Gesendet: Dienstag, 22. Juli 2003 15:40
Betreff: Re: how to limit COUNT(*)


> for example:
> 
> SELECT COUNT(*) as numfound FROM mytable WHERE mycondition;
> 
> in this query, mytable and mycondition are variable and on run time, 
> they are changed. I use this query to jump to the last page of a grid 
> form. sometimes the query may have more than million records and I 
> want to give a warning to the user to specify a condition to limit the

> number of records. I would like to count the records upto 10000 (for 
> example) and if the records are more than this, stop counting and ask 
> user to change the condition. to solve this problem I did something 
> like this:
> 
> SELECT one_field FROM mytable WHERE mycondition LIMIT 10001;
> 
> if the number of records of this query is equal to 10001, then I show 
> the warning message. but this query is not as fast of COUNT query. is 
> there any way to limit the first query?
> 
> thanks
> 
> ----- Original Message -----
> From: "gerald_clark" <[EMAIL PROTECTED]>
> To: "Mojtaba Faridzad" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Tuesday, July 22, 2003 9:15 AM
> Subject: Re: how to limit COUNT(*)
> 
> 
> > Perhaps you could post some examples of what you have tried. I don't

> > understand what you are asking.
> >
> > Mojtaba Faridzad wrote:
> >
> > >Hi,
> > >
> > >I guess there is no way to limit COUNT(*). Is that right? We cannot

> > >use
> the
> > >result of COUNT in WHERE condition or LIMIT doesn't help. In this 
> > >case so far I have retrieved a field and used LIMIT. Is there a 
> > >better way to control it?
> > >
> > >Thanks
> > >
> > >
> > >
> > >
> >
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
> >
> 
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]
> 

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to