At 10:06 -0500 1/28/02, Butch Bean wrote:
>I use this with all kinds of situations.
>I am using this function and others like it on tables with 100k to 3m
>They always work best when the field your looking for info on is indexed.
>Order By only causes a second process that seems unnecessary but I have not
>tested it directly
>Keep in mind that when I do use max() I am only interested in the highest
>number, I don't care how many are the highest or what they are. But...
>This will get you all or the record you are looking for using MySQL
>variables(I think someone else had this answer posted as well):
>SELECT @maxage:=max(age) from contacts;
>SELECT * FROM contacts WHERE age=@maxage;
>The above can be one call
>my $getbigage = $dbh->prepare(
> "SELECT @maxage:=max(age) from contacts;".
> "SELECT * FROM contacts WHERE age=@maxage;";
I don't believe this will work. @ in double-quoted Perl strings must
be escaped with a backslash. More important, you cannot issue multiple
queries at a time. In the case above, the MySQL will return an error
indicating a syntax error at the semicolon that occurs within the string.
>I use VB and Perl and the examples I could give you can get lengthy
>This example would be very slow in comparison
>> SELECT *
>> FROM contacts
>> ORDER BY age DESC
>> LIMIT 1