我正在尝试进行这样的查询:
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 不允许您要从中删除的表在条件的子查询中使用。