I have the folowwing SQL query
SELECT CustomerID FROM sales WHERE `Date` <= \'2012-01-01\' GROUP BY CustomerID
The query is executed over 11
Without knowing what your table schema looks like, it's difficult to be certain, but it would probably help if you added a multiple-column index on Date
and CustomerID
. That'd save MySQL the hassle of doing a full table scan for the GROUP BY
statement. So try ALTER TABLE sales ADD INDEX (Date,CustomerID)
.