Afficher un message
Vieux 06/10/2007, 10h49   #5
Séverin Richard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT MAX vs. SELECT / ORDER BYDESC / LIMIT

according to me
> SELECT MAX(order_total) AS order_max
> FROM orders
> WHERE customer = ...

is faster

with a limitation that is:
> SELECT MAX(order_total) AS order_max,****ID_ORDER****
> FROM orders
> WHERE customer = ...

will give u a random ****ID_ORDER****
(not the one with the max order)

and
> SELECT order_total AS order_max, ****ID_ORDER****
> FROM orders
> WHERE customer = ...
> ORDER BY order_total DESC
> LIMIT 1

will give u the right ****ID_ORDER****

That is the amazing way that the MAX() function works(fast).


yawnmoth wrote:
> I'm curious - which query is generally faster?:
>
> SELECT MAX(order_total) AS order_max
> FROM orders
> WHERE customer = ...
>
> ...or...
>
> SELECT order_total AS order_max
> FROM orders
> WHERE customer = ...
> ORDER BY order_total DESC
> LIMIT 1
>

  Réponse avec citation
 
Page generated in 0,05454 seconds with 9 queries