我试着做这样一个查询:
DELETE FROM term_hierarchy AS th
WHERE th.parent = 1015 AND th.tid IN (
SELECT DISTINCT(th1.tid)
FROM term_hierarchy AS th1
INNER JOIN term_hierarchy AS th2 ON (th1.tid = th2.tid AND th2.parent != 1015)
WHERE th1.parent = 1015
);
正如您可能看到的,如果同一个 tid 有其他的父关系,我想删除与1015的父关系。但是,这会产生一个语法错误:
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 th
WHERE th.parent = 1015 AND th.tid IN (
SELECT DISTINCT(th1.tid)
FROM ter' at line 1
我已经检查了文档,并且自己运行了子查询,所有这些似乎都已经检查完毕。有人知道这里出了什么问题吗?
更新 : 如下所述,MySQL 不允许在子查询中使用您正在删除的表。