Jump to content

[SOLVED] DELETE FROM (using "in") only deletes one row


Xeoncross

Recommended Posts

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+)

 

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.  ;D

 

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.