PDA

View Full Version : delete from multiple tables with join ?


tdmf
01-20-2005, 11:36 AM
$queryDelete = "
DELETE FROM table1,table2
WHERE table1.id=".$_GET['id']."
AND table2.id=".$_GET['id'];
Looks ok, but doesnt work.....$_GET['id'] is read correctly and available in all tables.....

any clues ?

Kiwi
01-20-2005, 11:45 AM
Read the documentation (http://dev.mysql.com/doc/mysql/en/DELETE.html).

DELETE table1,table2
FROM table1,table2
WHERE table1.id = get['id']
AND table2.id = table1.idNote, I've joined the tables - otherwise doing them in a single query makes little sense.

tdmf
01-20-2005, 12:02 PM
Hmmmm.........still doesnt work.
DELETE aa_db_surface2city, aa_db_surface2contact
FROM aa_db_surface2city, aa_db_surface2contact
WHERE aa_db_surface2city.cSurfaceID=".$_GET['id']."
AND aa_db_surface2contact.cSurfaceID = aa_db_surface2city.cSurfaceID";

Please help !

Thank you !

Kiwi
01-20-2005, 03:11 PM
What version of mySql are you using - it needs to be version 4 or greater (the details are in the docs). Otherwise that statement appears to be the correct syntax.

I would try hand coding the SQL into the command line and checking that it actually executes.

tdmf
01-20-2005, 03:57 PM
the console gives me the following error:

#1064 - You have an error in your SQL syntax near 'aa_db_surface2city,*aa_db_surface2contact
FROM aa_db_surface2city,*aa_db_surfa' at line 1

The documentations refers to the error as follows:
Error: 1064 SQLSTATE: 42000 (ER_PARSE_ERROR) Message: %s near '%s' at line %d

Now what does that tell me ?

tdmf
01-20-2005, 04:52 PM
ok my mysql version is: 3.23.57 - blame my host :confused:

is there any way to delete entries in multiple tables for this version ?

thanks a lot !

dniwebdesign
01-20-2005, 06:43 PM
Do seperate queries back to back...