Here is another possible approach:
SET @serial=0; SET @thisid=0; SELECT @serial := IF((@thisid != im.id), @serial + 1, @serial), @thisid := im.id, * FROM (`metadata` im) WHERE `im`.`id` = '00039' AND `current_revision` = 1 AND @serial < 5 ORDER BY `timestamp` DESC
This is not verified. Please let me know if you have any problems with this, and I can clarify.
Bas kuis
source share