Teck Posted February 3, 2008 Share Posted February 3, 2008 I'm having trouble deleting some data from a table of mine (about 3500 rows)... Now I have another table "attachments" which has a list of all of the attachments I want to keep basically (about 2500 rows)... What i need to do is delete any row from "forum_attachment" where "attachmentid" is not equal to any value in "attachid" Dunno if that makes any sense... This is the code i have, it will give you a better idea as to what im trying to do $query = "SELECT attachid FROM attachments ORDER BY id ASC"; $result = mysql_query($query) or die('Error:' . mysql_error()); while ($row = mysql_fetch_assoc($result)) { $attachid = $row['attachid']; $query = "DELETE FROM forum_attachment WHERE attachmentid != '$attachid'"; $result = mysql_query($query) or die('Error:' . mysql_error()); } If someone can point me in the right direction i would be grateful... Quote Link to comment https://forums.phpfreaks.com/topic/89150-solved-delete-and-use/ Share on other sites More sharing options...
trq Posted February 3, 2008 Share Posted February 3, 2008 DELETE FROM forum_attachment WHERE attachmentid NOT IN(SELECT attachid FROM attachments); Quote Link to comment https://forums.phpfreaks.com/topic/89150-solved-delete-and-use/#findComment-456548 Share on other sites More sharing options...
Teck Posted February 3, 2008 Author Share Posted February 3, 2008 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/89150-solved-delete-and-use/#findComment-456584 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.