List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:December 28 2001 10:09pm
Subject:Re: How to optimize this
View as plain text  
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

, which might be faster.

	Dan Nelson
How to optimize thisGoran Krajacic28 Dec
  • example scriptsBobby Brooks28 Dec
    • Re: example scriptsBogdan Stancescu29 Dec
  • Re: How to optimize thisDan Nelson28 Dec