Reputation: 272264
Suppose I have a datetime column in MySQL. How do I select all that have a datetime within 2500 seconds of the current datetime?
SELECT ALL where current_datetime - that_datetime < 2500 ...
Upvotes: 0
Views: 107
Reputation: 5345
Try this ...
SELECT * from table_name
where (extract ( epoch from current_datetime )
- extract (epoch from that_datetime)) < 2500
Upvotes: 1
Reputation: 25401
SELECT * FROM Table WHERE that_datetime > NOW() - INTERVAL 2500 SECOND
You want to do all the function calls and operation on constants as MySQL won't use indexes for fields used in any kind of expressions.
Upvotes: 1