Octavian Rasnita wrote:

Hi,

I have a table with a DATE type column and I want to search for more records
that have the same year and month.

I have tried searching with:

select ... where date_format(date, '%Y-%m')='2005-06' ...;

I know that if I apply a function to the date column, the index on that
column is not useful and I have seen that this query works very very very
slow, even though I have defined an index on the date column.

Exactly.

Are there any other ways to create this query in order to make it work
faster?

Thank you.
Teddy

Change the condition so that the indexed column is compared to a constant or range of constants. Thus, if you modify your condition like this,

  SELECT ... WHERE date BETWEEN '2005-06-01' AND '2005-06-30' ...;

mysql can use the index on column 'date'.

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to