脱裤子放屁的事情

今天一个开发人员报告说在删除数据的时候删不掉,执行的SQL语句如下: delete from tydb_hyzc_qyzl where memberid in (select c.memberid from tydb_hyzc_qyzl c,tydb_hyzc_grzl a where a.GRZL_username like ‘%@eyou%’ and c.memberid=a.memberid and c.QYZL_state<>1 and c.QYZL_state<>2);这样我也没看出什么问题。 我执行了一下,报了错误。错误代码为: ERROR 1093 (HY000): You can’t specify target table ‘clients’ for delete in FROM clause晕倒!我GOOGLE一下,在5.0的手册的上发现,原来不能在子查询中删除原有表的数据,并给了相关的提示和写法 DELETE FROM t WHERE … (SELECT … FROM t …); UPDATE t … WHERE col = (SELECT … FROM t …); {INSERT|REPLACE} INTO t (SELECT … FROM t …); Exception: The preceding prohibition does not apply if you are using a subquery for the modified table in the FROM clause. Example: UPDATE t … WHERE col = (SELECT (SELECT … FROM t…) AS _t …); Here the prohibition does not apply because a subquery in the FROM clause is materialized as a temporary table, so the relevant rows in t have already been selected by the time the update to t takes place. 我按照规则把SQL语句修改了一下就可以了。 delete from tydb_hyzc_qyzl where memberid in (select memberid from (select a.grzl_username,c.memberid,c.qyzl_state from tydb_hyzc_qyzl as c,tydb_hyzc_grzl as a where a.GRZL_username like ‘%@eyou%’ and c.memberid=a.memberid and c.QYZL_state<>1 and c.QYZL_state<>2) as ab); 我个人感觉这种写法简直就是脱裤子放屁费那二遍事。

你可能感兴趣的:(sql,C++,c,C#,Google)