Error: You can ' t specify target table ' xxx ' for update on FROM clause resolution

Source: Internet
Author: User

Problem:

A problem was encountered today when removing duplicate data from the MySQL database. The following script:

DELETE  from WHERE inch (SELECTMAXas fromGROUP by Name,age)

An error message will appear:

You can ' t specify target table ' Tempa ' for update in FROM clause

Basically, in the same statement, you cannot select some of the values in the same table first, and then update the table.

Workaround:

The above script needs to be modified as follows:

DELETE  from WHERE  not inch ( Select from  ,selectMAX as from GROUP by name,age) t)

You can avoid this error by adding a layer of intermediate tables when querying.

Error: You can ' t specify target table ' xxx ' for update on FROM clause resolution

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.