我通过此删除不断收到此错误。 Mysql版本是5.0.77。我想不出任何其他问题。我甚至创建了一个临时表来避免修改select中的表的问题。 :(
错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在'WHERE e.eid IN附近使用正确的语法 (选择 * FROM(SELECT w.eid 从'第3行
使用以下删除
DELETE
FROM emp2 e
WHERE e.eid IN
(SELECT *
FROM (SELECT w.eid
FROM works2 w,
emp2 e2,
dept2 d
WHERE w.did = d.did
AND d.managerid = e2.eid
AND e.salary > e2.salary
)
AS temp1
);
答案 0 :(得分:1)
尝试从您要删除的表中删除别名:
DELETE FROM emp2
WHERE eid IN (SELECT ...
答案 1 :(得分:0)
这可能有效:
DELETE e
FROM emp2 e
JOIN works2 w
ON w.eid = e.eid
JOIN dept2 d
ON w.did = d.did
JOIN emp2 e2
ON d.managerid = e2.eid
WHERE e.salary > e2.salary
或EXISTS
版本:
DELETE FROM emp2 e
WHERE EXISTS
( SELECT *
FROM works2 w,
emp2 e2,
dept2 d
WHERE w.did = d.did
AND d.managerid = e2.eid
AND e.salary > e2.salary
AND w.eid = e.eid
)
你究竟要删除什么?