Equivalent expressions

Equivalent expressions

am 22.08.2006 20:29:00 von Thomas Bartkus

Given a primary key field `RecNo` -

Are there any performance reasons to favor one of these two otherwise
equivalant expressions?

SELECT MAX(RecNo)
FROM SomeTable;

SELECT RecNo
FROM SomeTable
ORDER BY RecNo DESC
LIMIT 1;

Just curious.
Thomas Bartkus

Re: Equivalent expressions

am 23.08.2006 02:38:34 von zac.carey

Thomas Bartkus wrote:
> Given a primary key field `RecNo` -
>
> Are there any performance reasons to favor one of these two otherwise
> equivalant expressions?
>
> SELECT MAX(RecNo)
> FROM SomeTable;
>
> SELECT RecNo
> FROM SomeTable
> ORDER BY RecNo DESC
> LIMIT 1;
>
> Just curious.
> Thomas Bartkus

I think the performance differences (if any) would be easy enough to
test yourself.
Note though that there are at least a couple of situations where these
queries are not equivalent: If, for instance, a NULL value was provided
then this would appear at the top of the second query.