首页 » MySQL/TiDB/GoldenDB » MYSQL ERROR 1093 (HY000): You can’t specify target table ‘core_member’ for update in FROM clause

MYSQL ERROR 1093 (HY000): You can’t specify target table ‘core_member’ for update in FROM clause

今天删除mysql库中几条重复2次的记录,有个序列号member_id,取一个人最大用户名删除,没想到mysql语法还不一样

mysql> delete from core_member where member_id in(select max(member_id)  from core_member where user_id in(select user_id from core_user where email=’xiangtan@xiangtan.com’) group by  user_id);

ERROR 1093 (HY000): You can’t specify target table ‘core_member’ for update in FROM clause

如果把delete 换成from 可以,看来这就是mysql 独特的sql 语法所致上网一查说要把子查询当成个临时表启个别名再套一层,my god!

mysql> delete from core_member where member_id in( select mid from (select max(member_id) mid  from core_member where user_id in(select user_id from core_user where email=’xiangtan@xiangtan.com’) group by  user_id) c);
Query OK, 51 rows affected (0.01 sec)

打赏

目前这篇文章有1条评论(Rss)评论关闭。

  1. Odessa Kuenstler | #1
    2011-12-21 at 03:24

    The girls are incredibly hot by the way.