Reputation: 955
I have a table for connections that have the following structure:
->ip
->first (datetime of the entry creation)
->last (datetime of last update to the entry)
Datetimes are in the format Y-m-d H:i:s
.
Now I want to delete every entry that have last - first > 5 minutes
as true
. How can I do that in the SQL query?
Upvotes: 0
Views: 62
Reputation: 16468
use TIMESTAMPDIFF
DELETE FROM `tableName` WHERE TIMESTAMPDIFF(MINUTE,`first`,`last`) > 5
Upvotes: 1
Reputation: 12721
simply add it as where condition
DELETE FROM `table` WHERE `last` - `first` > 5;
Upvotes: 3