Jan Lyndon Jasa
Jan Lyndon Jasa

Reputation: 162

SELECT MAX() vs SELECT column ORDER BY column DESC LIMIT 1

sources said that the aggregate function MAX() has a better performance that select order desc limit 1

but after executing the query from a table with 43000 records, MAX() takes about 1.5 seconds and the other takes 350ms

and when both are used in inner queries, for about 1 minute MAX() is still executing while the other yield results for 94ms

can anyone enlighten me? I'd really appreciate it

Upvotes: 1

Views: 514

Answers (1)

PressingOnAlways
PressingOnAlways

Reputation: 12356

It is all about the INDEXes and the keys that you use. use EXPLAIN to see where your bottlenecks are - http://dev.mysql.com/doc/refman/5.0/en/using-explain.html.

Upvotes: 2

Related Questions