Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize cross-table update and data merging in MySQL

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to achieve cross-table update and data merging in MySQL, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

How to realize cross-table update and data merging in MySQL database

The example is like this: because of the needs of the work, it is necessary to add a lot of resource data to a table in the MYSQL database, because the amount of data is relatively large, so I think of dividing the table into several parts according to the type of resources ID, and then multiple people are responsible for a part of them respectively. Frankly speaking, it is extremely easy to divide the data into tables. You can select them by resource type ID and export them to different table names. However, when the data entry is finished, it is necessary to merge the entered data back to the source table. How can this be achieved? This article mainly introduces the realization of this process.

The requirements are as follows:

There are resource ID, resource type ID and some original content data in the source table sourceTable. Now add a field A, which is empty, so you must enter the content into the A field.

In order to improve the input efficiency, the source table sourceTable is divided into several tables (such as: jobTable1,jobTable2.), and the construction after the sub-table is completely the same as the source table sourceTable construction. Each person is responsible for the entry of one of the tables.

Taking jobTable1, one of the sub-tables, as an example, we recommend the measures to merge the entered data back to the source table sourceTable.

We use the update statement to update the field, which is held on a table, how to make cross-table updates?

How to realize cross-table update and data merging in MySQL database

Take a look at the following SQL statement:

UPDATE`sourceTable`, `jobTable1`SET`sourceTable`.`A` = `jobTable1`.`A`A`WERE`sourceTable`.`ID` = `jobTable1`.ID`ding.dingjian.org

The purpose of the above SQL statement is to update the contents of the A field in the sub-table jobTable1 back to the source table sourceTable, masking the A field contents in the source table sourceTable.

Because the ID in the subtable jobTable1 corresponds to the ID in the source table sourceTable, the WHERE clause is used to locate the registration.

UPDATE statements can not only update a single table, but also update across tables, and can make use of JOIN external join syntax.

The above is how to achieve cross-table update and data merging in MySQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report