From: Dan Nelson Date: December 28 2001 10:09pm Subject: Re: How to optimize this List-Archive: http://lists.mysql.com/mysql/94940 Message-Id: <20011228220907.GH77887@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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