> SELECT `order_date`
> FROM `orders`
> WHERE to_days( '2001-01-01' ) - to_days( `order_date` ) <= 365
joseph, you need to expand your test cases
that will probably return more than you think
as i mentioned, to_days( '2001-01-01' ) WILL ALWAYS BE LESS THAN
to_days(`order_date` ) whenever order_date is in 2001 OR LATER
thus the subtraction will result in a negative number
and all negative numbers are less than 365
in any case, if all you wanted was orders placed in 2001...
here is the easiest to understand --
... where year(order_date) = 2001
and here is the most efficient (assuming an index on order_date) --
... where order_date between '2001-01-01' and '2001-12-31'
or
... where order_date between '2001-01-01'
and date_add(date_add('2001-01-01', interval 1
year),interval -1 day)
use this second version if you are passing in the date of the 1st of the
year as a parameter
the efficiency comes in to play whenever the table is large
never put a function on a column, always compare the column to static values
rudy
____ � The WDVL Discussion List from WDVL.COM � ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
Send Your Posts To: [EMAIL PROTECTED]
To set a personal password send an email to [EMAIL PROTECTED] with the words: "set
WDVLTALK pw=yourpassword" in the body of the email.
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub
________________ http://www.wdvl.com _______________________
You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016
Please include the email address which you have been contacted with.