I need a MySQL statement to remove the oldest 10 entries from my table, however the closest I can get is this:
DECLARE ID INT;
SET ID = (SELECT CallbackID FROM callbacks ORDER BY CallbackID LIMIT 1 OFFSET 9);
DELETE FROM callbacks WHERE callbackID <= ID;
which is fine if there were always at least 10 entries, but when there are less, the ID is not set and therefore the delete statement fails.
Any ideas?
Thanks
EDIT:
Tried this too:
DECLARE ID INT;
SET ID = (SELECT CallbackID FROM callbacks ORDER BY CallbackID LIMIT 1 OFFSET 9);
if ID IS NOT NULL THEN
DELETE FROM callbacks WHERE callbackID <= ID;
END IF;
How about:
Yeah, it works
:)