I am not sure if this is possible, but I have a table of golf courses that have a "maintenance" field. 102 golf courses total.
Well, I would like to be able to display the latest date ANY of those 102 golf courses "maintenance" fields were updated.
Of course, I could create a field in the database, and manually save the date and time in there, but I wanted to see if maybe the mysql database keeps track of that ANYWAY?
Any help, thoughts, we be appreciated. Thanks!
One way is to add an auto-updating last_updated
field. However, the drawback here is that it will be updated when any field of that record is updated, not just the maintenance
field.
CREATE TABLE `golf_courses` (
`id` int UNSIGNED NULL AUTO_INCREMENT ,
`maintenance` text NULL ,
`last_maintenance` timestamp NULL ON UPDATE CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
);
Another solution, of course, as you mentioned, to record the time of the last maintenance manually:
UPDATE
`golf_courses` AS `g`
SET
`g`.`maintenance` = 'new maintenance value',
`g`.`last_maintenance` = NOW();