You are correct... my apologies, I was thinking in VB where I built a
handler to let me sent multiple sql statements in one chunk and where the
'@' doesn't matter.

BB

-----Original Message-----
From: Paul DuBois [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 28, 2002 11:28 AM
To: [EMAIL PROTECTED]; Richard Morton; DL Neil;
[EMAIL PROTECTED]
Subject: RE: Selecting the row with largest number in a column


At 10:06 -0500 1/28/02, Butch Bean wrote:
>Richard,
>
>I use this with all kinds of situations.
>I am using this function and others like it on tables with 100k to 3m
>records.
>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
>
>Perl Example:
>
>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.

>.
>.
>$getbigage->execute();
>...$getbigage->fetchrow_array()...
>.
>
>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
>
>Butch Bean


---------------------------------------------------------------------
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

Reply via email to