开发者

MySql syntax error; Deleting from two tables in one query possible?

Is it not possible to perform two deletes in one query by separating them with a semicolon?

Here is my query:

$query="DELETE FROM $sql_table
WHERE EXISTS 
    (
    SELECT 1
    FROM classified
    WHERE classified.poster_password = '$pass'
    AND classified.ad_id = '$id'
    AND classified.classified_id = $sql_table.classified_id
    );
DELETE FROM classified
WHERE classified.poster_password = '$pass'
AND classified.ad_id = '$id'";

This gives this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM classified WHERE classified.poster_password = 'xxxxxxx' 开发者_如何学运维at line 10

Please help me solve this one, it is starting to give me a headache. I need it in one query...

Thanks


You didn't mention which PHP function you use to submit this to MySQL. MySQLi's multi_query can handle this.


Take a look at transactions

Using MySQL Transactions

BEGIN

COMMIT


you can build tmth like this

DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜