日期:2014-05-16  浏览次数:20715 次

MySql 中的 DELETE 真差劲...
这样写正常:
------------------
SELECT   id   FROM   tree   WHERE   father!=0   AND   father   NOT   IN   (SELECT   id   FROM   tree   );

这样写出错:
------------------
DELETE   FROM   tree   WHERE   father!=0   AND   father   NOT   IN   (SELECT   id   FROM   tree   );

ERROR   1093   (HY000):   You   can 't   specify   target   table   'tree   '   for   update   in   FROM   clause



------解决方案--------------------
右侧中写的相当明确:目前,您不能从一个表中删除,同时又在子查询中从同一个表中选择
------解决方案--------------------
呵呵~~~~~~~
------解决方案--------------------
DELETE FROM tree WHERE father!=0 AND father NOT IN (SELECT id FROM tree );
这样的sql在什么数据库会执行?
都应该不会执行的。
------解决方案--------------------
13.2.1. DELETE语法
单表语法:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[WHERE where_definition]
[ORDER BY ...]
[LIMIT row_count]
多表语法:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
tbl_name[.*] [, tbl_name[.*] ...]
FROM table_references
[WHERE where_definition]
或:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
FROM tbl_name[.*] [, tbl_name[.*] ...]
USING table_references
[WHERE where_definition]