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 Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/ Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 As in LIMIT 1? yes. Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458500 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] Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458501 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"); Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458502 Share on other sites More sharing options...
pdkv2 Posted February 5, 2008 Share Posted February 5, 2008 Yes but remove "ORDER BY time" Cheers ! Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458505 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 Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458520 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. Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458525 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?? Link to comment https://forums.phpfreaks.com/topic/89514-limit-on-sql-delete/#findComment-458540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.