MySql Tutorial: update data between two tables _ MySQL

Source: Internet
Author: User
Tags mysql tutorial
MySql Tutorial: There are two tables for updating data between two tables. The structure is as follows:

A (id, sex, email, public)

B (id, depart, salary)

As demand changes, a public field must be added to B, and the value of the public field must be the same as that in the record with the same id in Table.

It is easy to add a field, and you just need to directly alter it. However, if you haven't done any data update between tables before, you just need to google it. it turns out that many people write this in this way:

UPDATE B SET public =. public FROM a WHERE B. id =. id, but it is difficult to live and live in Mysql. it always prompts that there is an error. later, I checked the information and found that mysql does not support the from clause in update, many people on the Internet may write data for sqlserver or other databases. Rewrite the SQL statement as follows:

UPDATE B, a SET B. public = a. public WHERE B. id = a. id to learn something, recorded here.

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.