When I try this query:
SELECT DATE_ADD(upg_date, INTERVAL 30 DAY) AS 'upgrade_date'
WHERE id=12345
it returns me the record with the correct value, but when I add a condition like this:
SELECT DATE_ADD(upg_date, INTERVAL 30 DAY) AS 'upgrade_date'
WHERE id=12345
AND 'upgrade_date' < NOW()
it returns an empty result set. But value of the upgrade_date is lower than current date.
What’s wrong?
You cannot use the
aliasin thewhereclause. It should be the original column name.From the MySQL Manual:
It is not allowable to refer to a column alias in a WHERE clause, because the column value might not yet be determined when the WHERE clause is executed.