phpbar.de logo

Mailinglisten-Archive

SELECT mit EXISTS geht / DELETE nicht

SELECT mit EXISTS geht / DELETE nicht

Hannes Korte email at hkorte.com
Mit Mai 26 18:25:02 CEST 2004


Hi,

ich komm grad nicht weiter. Ich habe eine SELECT-Abfrage, die problemlos
funktioniert, aber wenn ich das SELECT * durch ein DELETE ersetze, kommt
folgende Fehlermeldung:

#1064 - 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
'WHERE  NOT EXISTS (  SELECT  * FROM  `abc` [...]

Query:

SELECT * FROM `table1` AS t1
WHERE NOT EXISTS (SELECT * FROM `table2` AS t2 WHERE t2.t1id = t1.id)
AND EXISTS (SELECT * FROM `table3` AS t3 WHERE t3.t1id = t1.id);
--> funktioniert!

bzw:

DELETE FROM `table1` AS t1
WHERE NOT EXISTS (SELECT * FROM `table2` AS t2 WHERE t2.t1id = t1.id)
AND EXISTS (SELECT * FROM `table3` AS t3 WHERE t3.t1id = t1.id);
--> funktioniert nicht!

Warum geht das mit SELECT, aber nicht mit DELETE?
Ich k�nnte hier nat�rlich einfach erst die IDs abfragen und dann mit DELETE
[...] WHERE id IN (...); die Datens�tze l�schen, das w�re aber irgendwie
h�sslich. Das muss doch mit einem Statement gehen.

F�llt euch da was zu ein?

--
Gru�
Hannes


php::bar PHP Wiki   -   Listenarchive