Search code examples
sqlmysqlmysql-error-1064

please help me construct this MYSQL Query (date / time)


I would like to construct a query that fetches results that occurred between NOW and 15 minutes ago, im getting a mysql error when I try the following , can you help me? thanks

SELECT *
 WHERE user_id = '000'
   AND date_time < now( )
   AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE) 

Error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id = '000' AND date_time < now( ) AND date_time > DATE_SUB( now( ) ' at line 2


Solution

  • it lacks FROM TABLENAME

    SELECT * FROM TABLENAME
    WHERE user_id = '000'
    AND date_time < now( )
    AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE)