I am working with a table where records do not get updated. New revisions get inserted when a change happens. Revisions are associated by the serial field AND the location field, which means a primary record and its corresponding revisions in the same table have a unique serial number within that location, but the serial may be reused in another location. The revision field is incremented up by 1 with each revision.
I am attempting to select all records with a status of 4, 5, or 6 where there is NO other record with a higher revision number than its own where the serial and location match. I am not certain how to do this.
CREATE TABLE `table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`serial` int(10) NOT NULL DEFAULT '0',
`location` int(10) NOT NULL DEFAULT '0',
`revision` int(3) NOT NULL DEFAULT '0',
`status` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
You need to use a subquery :
updated