MySQL a more specific problem: You can ' t specify target table ' Sys_user ' for update in FROM clause

Source: Internet
Author: User

SELECT  from Sys_user

Results:

The Create_user_uin_tree in the table identifies who created the record.

When creating a new user, the following SQL is available based on the UIn of the currently logged on user and the newly created user uin:

Select concat (ifnull (Create_user_uin_tree,concat ('_',2,' _ '),'|_', ' a', ' _ ') from   where uin=2

Results:

Then the modified Create_user_uin_tree's identity SQL is:

UpdateSys_userSetCreate_user_uin_tree=(SelectConcat (Ifnull (Temp. Create_user_uin_tree,concat ('_',2,'_')),'|_',' the',"_") fromSys_userTemp where Temp. UIn=2)whereUIn=  the;

Error message:

Error code:1093. You can ' t specify target table ' Sys_user ' for update in FROM clause 0.000 sec

Reason for the answer on the network :

This is not the way to use MySQL. (wait for MySQL to upgrade it). The English error message means that you cannot select some values from the same table first, and then update the table (in the same statement).

Adjusted the following SQL:

UpdateSys_userSetCreate_user_uin_tree=(Select Temp. Tree from(SelectConcat (Ifnull (Create_user_uin_tree,concat ('_', the,'_')),'|_','98',"_") asTree fromSys_userwhereUIn= the)Temp)whereUIn= 98;

I will be a subset,

Select concat (ifnull (Create_user_uin_tree,concat ('_',"the _ '),'|_', '98' as Tree   from where uin=$Temp

and then

Select Temp From (subset)

subset so that neither select nor update is the same table. This problem is solved perfectly.

MySQL a more specific problem: You can ' t specify target table ' Sys_user ' 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.