views:

41

answers:

3

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

+1  A: 

Take a look at transactions

Using MySQL Transactions

BEGIN

COMMIT
Sres
A: 

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

Manos Dilaverakis
+1  A: 

you can build tmth like this

DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
GOsha
to clarify a bit more, build the SELECT that will show the record you want to DELETE, then switch the "SELECT fields," with "DELETE table", keeping FROM and everything after. Only records in the tables immediately following DELETE with be deleted.
Brent Baisley
i was just giving a path to think) with such requests you can do all much easier
GOsha