Why this query does not select any rows

What is wrong with this SQL? It seems like it should work, but it is not.

utc_time is a datetime field.

SELECT id FROM `foo` WHERE utc_time > now() AND utc_time <= DATE_ADD(curdate(),INTERVAL 24 day); 

The explanation says the Where clause is not possible.

utc_time is a datetime type. Here is an example utc_time value: 2011-06-21 00:45:00

+4
source share
1 answer

utc_time() is a built-in function . Even without parentheses, utc_time still returns the current UTC time.

Escape in a column named utc_time . This works (I tested it):

 SELECT id FROM `foo` WHERE `utc_time` > now() AND `utc_time` <= DATE_ADD(curdate(),INTERVAL 24 day); 

Another example of why it is a bad idea to use reserved words or function names as column / table names.

+2
source

All Articles