views:

19

answers:

3

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

+1  A: 

it lacks FROM TABLENAME

SELECT * FROM TABLENAME
WHERE user_id = '000'
AND date_time < now( )
AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE) 
Luis Melgratti
DOH! thank you!
sebb
+2  A: 

You need to select FROM a table :)

barrycarter
A: 

You're missing the FROM statement

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