MySQL update nesting

Source: Internet
Author: User
Tags mysql update

MySQL update nesting when we want to retrieve the data d1 in col1 (for example, the current blog access volume) of column id = 5 from table 1 in MySQL, when the table1 attribute p1 is updated to d1 + 1, we may think of using this SQL statement [SQL] <span style = "font-size: 18px; "> update table1 set col1 = (select col1 from a where id = 5) + 1 where id = 5; </span> but it is returned in the MySQL Command column tool: ERROR 1093 (HY000): You can't specify target table 'Forum _ members 'for update in FROM clause the original database has this rule: the updated table is not allowed in the UPDATE subquery. That is to say, when updating a, you cannot select col from a later. If the table is different, there is no problem. Think of a solution: [SQL] UPDATE table1 a inner join table1 B ON B. id = 1 AND a. id = B. id SET a. col = B. col + 1

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.