Which query is optimized when I get monthly data with respect to sale.purchase_date using MySQL? -


i have same result when execute both queries different functions. wanted know query optimized or logically correct (see query 1 , 2 below).

i monthly data respect sale.purchase_date

query 1

select sales.purchase_date `sales`  sales.purchase_date  '2012-06-%'; 

query 2

select sales.purchase_date `sales`  month(sales.purchase_date) = '6' , year(sales.purchase_date) = '2012'; 

both of require table scan because need examine purchase_date see if row in , can't use index. suggest use between query can make use of index on purchase_date:

where sales.purchase_date between '2012-06-01' , '2012-06-30' 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -