From: "Frank Bax"
> I have a table with datetime field and I would like to select all data
> older than "X" weeks, where "X" is a variable in my php script.

SELECT (.....) WHERE `datetime_field` < NOW() - INTERVAL (7*X) DAY

This way you compare the datetime field with a constant (the expression
results in a constant), so MySQL can use an index if there is one for the
datetime field.

Regards, Jigal.


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

Reply via email to