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? Link to comment https://forums.phpfreaks.com/topic/258442-deleting-old-records/ 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? Link to comment https://forums.phpfreaks.com/topic/258442-deleting-old-records/#findComment-1324773 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 Link to comment https://forums.phpfreaks.com/topic/258442-deleting-old-records/#findComment-1324776 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. Link to comment https://forums.phpfreaks.com/topic/258442-deleting-old-records/#findComment-1325235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.