MySQL can ' t specify target table for update on FROM clause

Source: Internet
Author: User

Translation: MySQL cannot specify the updated target table in the FROM clause

SOURCE SQL statement:

[SQL]View PlainCopyprint?
    1. Delete from t_official_sys_user
    2. where user_name in (SELECT user_name from t_official_sys_user b Group by b. ' User_name ' Having count (1) > 1)



The following error was reported:

[SQL]View PlainCopyprint?
  1. [SQL]
  2. Delete from t_official_sys_user
  3. where user_name in (SELECT user_name from t_official_sys_user b Group by B. ' user_name ' having COUNT (1) > 1)
  4. [ERR] 1093-you can' t specify target table ' T_official_sys_user ' for update on from clause



The resolution code is as follows:

[SQL]View PlainCopyprint?
  1. Delete from t_official_sys_user
  2. where user_name in (
  3. Select User_name from
  4. (
  5. SELECT user_name from t_official_sys_user b Group by B. ' user_name ' having count (1) > 1
  6. ) as temtable
  7. );

Analysis:

First, put the target to be deleted to a temporary table and then assign the conditions to be removed to this temporary table.

http://blog.csdn.net/bluestarf/article/details/46622455

Http://www.cnblogs.com/nick-huang/p/4412818.html

MySQL can ' t specify target table for update on FROM clause

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.