I am trying to select the Max('id') with the difference of 5 minutes between two timestamp in mysql.
My timestamp field is sent
I did
SELECT Max('id') FROM `mytable` WHERE TIMESTAMPDIFF(MINUTE, `sent`, NOW()) > 5
But this did not work. It sent me and empty result
This is my table structure
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`from_id` int(10) unsigned NOT NULL,
`to_id` int(10) unsigned NOT NULL,
`message` text NOT NULL,
`sent` int(10) unsigned NOT NULL DEFAULT '0',
`read_statu` tinyint(1) unsigned NOT NULL DEFAULT '0',
`is_deleted` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `to` (`to_id`),
KEY `from` (`from_id`),
KEY `direction` (`is_deleted`),
KEY `read` (`read_statu`),
KEY `sent` (`sent`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=201 ;
INSERT INTO `mytable` (`id`, `from_id`, `to_id`, `message`, `sent`, `read_statu`, `is_deleted`) VALUES
(1, 1, 2, 'Juste un test pour moi meme', 1425729597, 1, 0),
(2, 2, 1, 'Hello', 1425729612, 1, 0),
(3, 2, 1, ' <3 (L) :prayer: :tkh: :heart: :-$ ', 1425729922, 1, 0),
(4, 2, 1, ' <3 (L) :prayer: :tkh: :heart: :-$ ', 1425729927, 1, 0),
(5, 1, 2, 'Ok', 1426010868, 0, 0);
Please How to select Max(id) with the difference between two timestamp superior to five minute in Mysql ?
Thanks