Reputation:
I'm trying to create a query which will get the results that were inserted in the last 10 seconds:
SELECT *
FROM table
WHERE client_id = 1
AND hash = 'x'
AND insert_time >= current_timestamp - **10 seconds**
I've been searching how to subtract 10 seconds from the current timestamp, but I didn't succeed yet.
Upvotes: 3
Views: 16515
Reputation: 13571
Due to reference you should use SUBTIME
...
and insert_time >= SUBTIME(current_timestamp,'0 0:0:10.000000');
Alternatively you can use INTERVAL
as following:
...
and insert_time >= SUBTIME(current_timestamp, INTERVAL 10 SECOND);
Notice that due to reference
When invoked with the INTERVAL form of the second argument, SUBDATE() is a synonym for DATE_SUB().
Upvotes: 9
Reputation: 37803
You Want:
insert_time >= DATE_SUB(current_timestamp, INTERVAL 10 SECOND)
Upvotes: 0