blueman378 Posted February 5, 2008 Share Posted February 5, 2008 well the title says it all really, i dont want to play around with my db too much so i am asking this here first, can you place a limit on a sql delete query? thanks guys Quote Link to comment Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 As in LIMIT 1? yes. Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted February 5, 2008 Share Posted February 5, 2008 YEs DELETE [LOW_PRIORITY] [QUICK] [iGNORE] FROM tbl_name [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] Quote Link to comment Share on other sites More sharing options...
blueman378 Posted February 5, 2008 Author Share Posted February 5, 2008 so this should work? mysql_query("DELETE * FROM latest ORDER BY `time` LIMIT 20,100"); Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted February 5, 2008 Share Posted February 5, 2008 Yes but remove "ORDER BY time" Cheers ! Quote Link to comment Share on other sites More sharing options...
blueman378 Posted February 5, 2008 Author Share Posted February 5, 2008 hmm thats a problem, because what i am trying to do is i have a column called time, which contains the time it was inserted (duh) anyway i want to delete the oldest result if there are more than 20 so thats why i wanted order by time Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted February 5, 2008 Share Posted February 5, 2008 i think this query was asked by you in some other thread also. Quote Link to comment Share on other sites More sharing options...
shergar1983 Posted February 5, 2008 Share Posted February 5, 2008 Can you not just select the last record first? Assuming this table has a unique key (auto-increment) you could select MAX or if you need to delete more than one, place it in a select loop?? 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.