Equivalent expressions
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
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.