Xeoncross Posted July 25, 2007 Share Posted July 25, 2007 I have been working with this "IN" clause but I can't get this statement to kill more than one database row. <?php $query = 'DELETE FROM `comments` WHERE `id` in (\''. mysql_real_escape_string($id_list). '\') LIMIT '. count($ids); ?> > >DELETE * FROM `comments` WHERE `id` in ('85,84,82') LIMIT 3; > I only deletes one row instead of all three. (MySQL 4+) Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/ Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 Let me guess, `id` is some kind of INT column type, right? So why are you feeding it a string, '85,84,82'? Try removing those quotes. Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-307259 Share on other sites More sharing options...
Xeoncross Posted July 25, 2007 Author Share Posted July 25, 2007 Yep, that is what it was. I tried it without quotes the first time but I go an error... Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-307276 Share on other sites More sharing options...
fenway Posted July 30, 2007 Share Posted July 30, 2007 Yep, that is what it was. I tried it without quotes the first time but I go an error... What error? Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-311117 Share on other sites More sharing options...
Xeoncross Posted August 6, 2007 Author Share Posted August 6, 2007 Well, now I am having trouble with another "in" statement. Also, I am afraid I don't remember what error that was fenway. DELETE FROM `content`, `posts` WHERE `posts.id` = `content.id` AND `content.id` in (56) LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-316830 Share on other sites More sharing options...
Illusion Posted August 6, 2007 Share Posted August 6, 2007 Try this DELETE FROM `content`, `posts` USING `content`,`posts` WHERE `posts.id` = `content.id` AND `content.id`=56 LIMIT 1 or DELETE `content`, `posts` FROM `content`,`posts` WHERE `posts.id` = `content.id` AND `content.id`=56 LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-316848 Share on other sites More sharing options...
Xeoncross Posted August 6, 2007 Author Share Posted August 6, 2007 Well, I need it to be an "IN" statement because I am deleting many ids usually... I don't have any trouble with single ids. DELETE FROM `content`, `posts` WHERE `posts.id` = `content.id` AND `content.id` in (56,60,49,34) LIMIT 4 DELETE FROM `content`, `posts` WHERE `content.id` in (56,60,49,34) LIMIT 4 Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-316859 Share on other sites More sharing options...
Xeoncross Posted August 8, 2007 Author Share Posted August 8, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-318645 Share on other sites More sharing options...
akitchin Posted August 8, 2007 Share Posted August 8, 2007 illusion was right - when specifying multiple tables in the DELETE statement, you have to explicitly differentiate between tables being used solely for the WHERE clause and those you actually want to DELETE from. have a look in the manual for syntax, but you can use DELETE table1, table2 FROM table1, table2 or DELETE FROM table1, table2 USING table1, table2 Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-318649 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 i guess you can delete the record form two table if you do something like joining before get the item to delete like DELETE FROM table1,table2 where tqable1.x=table2.x and table1.x in () i guess something like that will work Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-319033 Share on other sites More sharing options...
Xeoncross Posted September 20, 2007 Author Share Posted September 20, 2007 Ok, I finally got it. DELETE FROM `posts`, `content` USING `posts`, `content` WHERE content.id = posts.id AND posts.id in (63,62) Deleted rows: 4 (Query took 0.0011 sec) Quote Link to comment https://forums.phpfreaks.com/topic/61721-solved-delete-from-using-in-only-deletes-one-row/#findComment-351915 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.