MySQL can ' t specify target table for update in from Clau

Source: Internet
Author: User
Tags mysql in

MySQL in the can ' t specify target table for update in the FROM clause error means that you cannot select some of the values in the same table first, and then update the table (in the same statement). For example, the following SQL:

The

code is as follows:


Delete from tbl where ID in


(


select Max (ID) from TBL a where EXISTS


        (


Select 1 from tbl B where A.tac=b.tac GROUP by TAC has count (1) >1


        )


GROUP BY TAC


)

Rewrite it to the following line:

The

code is as follows:


Delete from tbl where ID in


(


Select a.ID from


    (


Select MAX (ID) ID from tbl a where EXISTS


        (


Select 1 from tbl B where A.tac=b.tac GROUP by TAC has count (1) >1


        )


GROUP BY TAC


) A


)

That is, the result of the select is then select through the middle table, which avoids the error. Note that this problem occurs only in Mysql,mssql and Oracle.

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.