In the last episode (Dec 28), Goran Krajacic said:
> How to optimize this query:
>
> SELECT col1, col2, MAX(col3) FROM Table WHERE col4>2 AND col5 = 2 GROUP BY col3
>LIMIT 1;
Try a compound index on (col5,col4), or if you really want speed,
(col5,col4,col3,col2,col1), which will let mysql use the index for the
SELECT fields as well :)
Your query can also be written
SELECT col1, col2, col3 FROM Table WHERE col4>2 AND col5 = 2 ORDER BY col3 DESC LIMIT
1;
, which might be faster.
--
Dan Nelson
[EMAIL PROTECTED]
---------------------------------------------------------------------
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