我试图做这样的查询:
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
);
您可能会说,如果同一提示有其他父母,我想删除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不允许在子查询中使用该条件从中删除要删除的表。
DELETE t FROM table t ...