MySQL Update select usage

Source: Internet
Author: User

The table was previously updated with SQL Server, UPDATE statement:
Update a set a.xx= (select yy from B); Yes, I can.
However, in MySQL, you cannot directly use the result of the set Select,

UPDATE ecs_users_copy
SET ' user_name ' = (
SELECT
' Identity_card '
From
Ecs_users_copy
WHERE
LENGTH (identity_card) = 18
and LENGTH (user_name)! = 18
)

This is the wrong way!

You must use INNER join:

Demo1

Update a INNER JOIN (select table from B) C set a.id = a.id where a xxx

Demo2

UPDATE Ecs_users_copy as a
INNER JOIN (SELECT ' identity_card ', ' user_name ' from ecs_users_copy) b
SET A.user_name = A.identity_card
WHERE
a.user_id =a.user_id and (LENGTH (a.identity_card) = 18
and LENGTH (a.user_name)! = 18)

The more things you use, the easier it is to confuse ~ ~

Write for one weeks Java, and then write back to PHP

\exception E

, suddenly found out why not, the original PHP exception is a $ ~ ~ ~ and Java did not ~ ~ ~

MySQL Update select usage

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.