MySQL Update SQL error: You can ' t specify target table ' Wms_cabinet_form ' for update in FROM clause

Source: Internet
Author: User
Tags mysql update sql error

The database has two fields in the wrong position, you want to change them. Because there is no database write permission, it needs to be implemented with SQL statements. Originally thought to be simple

Update table A set a. Field a= (select B field from table where id=?), set a. Field b= (Select a field from table where id=?) where id=? , and the results reported this problem.

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

Google later found that it is the problem of MySQL itself, it is necessary to write:

Update table SET field a= (select T1. field b from (SELECT * from table where id=?) T1), set field b= (Selet t2. Field A from (SELECT * from table where id=?) T2) where id=?

For your own example:

UPDATE Ec_payment_type
SET Return_url = (
SELECT
A.notify_url
From
(
SELECT
*
From
Ec_payment_type
WHERE
payment_type_id = 10
) A
),
Notify_url = (
SELECT
B.return_url
From
(
SELECT
*
From
Ec_payment_type
WHERE
payment_type_id = 10
) b
)
WHERE
payment_type_id = 10

MySQL Update SQL error: You can ' t specify target table ' Wms_cabinet_form ' for update in 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.