wrathican Posted October 1, 2008 Share Posted October 1, 2008 hi there people, i need a single mysql query that would delete all but the first row in a table. thanks Wrathican Link to comment https://forums.phpfreaks.com/topic/126628-mysql-delete-and-php/ Share on other sites More sharing options...
trq Posted October 1, 2008 Share Posted October 1, 2008 Define first row. Link to comment https://forums.phpfreaks.com/topic/126628-mysql-delete-and-php/#findComment-654800 Share on other sites More sharing options...
envexlabs Posted October 1, 2008 Share Posted October 1, 2008 You'll have to figure out the id of the id of the first row: $query = mysql_query('SELECT `id` FROM `table` ORDER BY `id` ASC'); $result = mysql_fetch_assoc($query); $delete = mysql_query("DELETE FROM `table` WHERE `id` = '$result[id]' LIMIT 1"); Link to comment https://forums.phpfreaks.com/topic/126628-mysql-delete-and-php/#findComment-654808 Share on other sites More sharing options...
trq Posted October 1, 2008 Share Posted October 1, 2008 If you where going to use that type of logic you could simply use... DELETE FROM tbl WHERE id NOT IN(MIN('id'])); Link to comment https://forums.phpfreaks.com/topic/126628-mysql-delete-and-php/#findComment-654811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.