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
dnelson@stripped