CREATE TABLE IF NOT EXISTS `docs` (
`id` int(6) unsigned NOT NULL,
`rev` int(3) unsigned NOT NULL,
`content` varchar(200) NOT NULL,
PRIMARY KEY (`id`,`rev`)
) DEFAULT CHARSET=utf8;
INSERT INTO `docs` (`id`, `rev`, `content`) VALUES
('1', '1', 'The earth is flat'),
('2', '1', 'One hundred angels can dance on the head of a pin'),
('1', '2', 'The earth is flat and rests on a bull\'s horn'),
('1', '3', 'The earth is like a ball.');
/////////////////////////////////////////////////////////
Then the actual Query:
SELECT a.id, a.rev, a.content
FROM `docs` a
INNER JOIN (
SELECT id, MAX(rev) rev
FROM `docs`
GROUP BY id
) b ON a.id = b.id AND a.rev = b.rev;
SELECT a.*
FROM `docs` a
LEFT OUTER JOIN `docs` b
ON a.id = b.id AND a.rev < b.rev
WHERE b.id IS NULL;
a
is some kind of placeholder?
Where would one go to find an explaination of this IN ENGLISH?
I'm hoping someone would walk us through this and make it understandable.
Thank you!