MySQL Forums
Forum List  »  Newbie

Re: Query table and retriving results
Posted by: Rick James
Date: June 01, 2016 09:55AM

> where Entry_Date like '2016%'
> where left(entry_date,4)='2016'

Both require conversion of `Entry_date`, so neither can use an index. This can use an index:

    WHERE entry_date >= '2016-01-01'
      AND entry_date  < '2016-01-01' + INTERVAL 1 YEAR

But _will_ it use an index? It depends on the distribution of dates in the table and the index and whether the WHERE has other clauses. You can try

    INDEX(entry_date)

For further discussion, please provide SHOW CREATE TABLE and the SELECT in question. You could also read http://mysql.rjweb.org/doc.php/index_cookbook_mysql .

Options: ReplyQuote


Subject
Written By
Posted
Re: Query table and retriving results
June 01, 2016 09:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.