I use this to manage temporary data quite a bit – for example, server logs of a chat, where you only want to keep the X most recent – after every write, or as a scheduled task, I delete all but the last 10. Here’s a query to do that simply (obviously you could use SELECT or UPDATE instead of DELETE… the principal is the same):

DELETE FROM table
	WHERE whatever = :something
	AND id < ( 
		SELECT min(id) FROM ( 
			SELECT id FROM table
			WHERE whatever = :something
			ORDER BY id DESC LIMIT 10 ) 
		AS t)