I currently have PHP code that processes the logic for this, because I do not know how to process it in SQL. I want to create a stored procedure that will delete all lines except the 5 most recent for this config_id. IE config_id = 5 is passed to the SP, so it knows which config_id it wants to clear.
CREATE TABLE `TAA`.`RunHistory` (
`id` int(11) NOT NULL auto_increment,
`start_time` datetime default NULL,
`stop_time` datetime default NULL,
`success_lines` int(11) default NULL,
`error_lines` int(11) default NULL,
`config_id` int(11) NOT NULL,
`file_id` int(11) NOT NULL,
`notes` text NOT NULL,
`log_file` longblob,
`save` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=128 DEFAULT CHARSET=utf8;
The newest one will be determined by start_time, if stop_time is NULL, but NOT the last, it must be deleted (stop_time can be null if the start was unceremoniously killed).
source
share