mcmuney Posted March 7, 2012 Share Posted March 7, 2012 What would be the SQL to keep the most current 10,000 records and delete everything else? Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2012 Share Posted March 7, 2012 Has your table got a timestamp or similar field? Quote Link to comment Share on other sites More sharing options...
mcmuney Posted March 7, 2012 Author Share Posted March 7, 2012 Yes, I believe it's in UNIX: 1330345475 Quote Link to comment Share on other sites More sharing options...
cpd Posted March 8, 2012 Share Posted March 8, 2012 This may work but is dependant upon a rowID being present and the rowID having been incremented by 1 every time. DELETE FROM `tblName` WHERE `rowID` <= ((SELECT COUNT(*) FROM `tblName`) - 10000) or possibly DELETE FROM `tblName` WHERE `rowID` <= ((SELECT `rowID` FROM `tblName` ORDER BY `rowID` DESC LIMIT 1) - 10000) Give it a got haven't got time to test it right now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.