我必须消灭那些在2010年进行维修的叫做“奥斯卡”的技术人员。
我必须先删除他们进行的维修,然后删除称为“奥斯卡”的技术人员。我在两个陈述中做到这一点:
DELETE FROM Reparacion WHERE cuit_tec IN(SELECT Tec.cuit
FROM Tecnico Tec
WHERE Tec.nombre like 'oscar%'
AND NOT EXISTS(SELECT 1
FROM Reparacion Rep
WHERE Rep.cuit_tec = Tec.cuit
AND Fecha BETWEEN '2010-01-01' AND '2010-12-31'));
和
DELETE FROM
Tecnico AS Tec
WHERE
Nombre like 'oscar%' AND
NOT EXISTS (SELECT
1
FROM
Reparacion AS Rep
WHERE
Rep.Cuit_tec = Tec.Cuit AND
Fecha BETWEEN '2010-01-01' AND '2010-12-31');
这会引发错误消息:
"Error Code: 1093. You can not specify target table 'Repair' for update in FROM clause"
"Error Code: 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 'AS Tec WHERE Name = 'oscar' AND NOT EXISTS (SELECT 1 FROM R ' at line 2 "
sqlfiddle:http ://sqlfiddle.com/#!2/9438d