MySQL in your can ' t specify target table for update in FROM clause

Source: Internet
Author: User

Duplicate records in a delete table using MySQL

Delete from the user where username in (select the User name form (select username from the user group by username have count (usernam e) (>1));

Encounter MySQL error you can ' t specify target table to update in FROM clause

Internet Baidu is the original MySQL is not allowed to select out some values in the same table, and then update the table (in the same statement), this problem only occurs in Mysql,sqlserver and Oracle does not occur this problem

Workaround: Pass the result of the select again through the intermediate table select again

Delete from the user where username in (the Select A.username from (select username from the user group by username have count (Userna Me) (>1) a);

So the delete and select are not the same table.

MySQL in your can ' t specify target table for update in FROM clause

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.