MySQL databaseHow to ImplementCross-Table updateAndData MergingWhat about it? This article uses an example to introduce how to achieve cross-Table update and data merging.
The example is as follows: a lot of resource data must be appended to a table in the MYSQL database because of the large data volume, therefore, the table is divided into several parts based on the resource type ID, and multiple people are responsible for one of the parts. Frankly speaking, it is extremely easy to split data into tables. You can select and export the data into different table names based on the resource type ID. However, when the data entry ends, it is necessary to merge the entered data into the source table. How can this problem be achieved? This article mainly introduces the implementation of this process.
The requirements are as follows:
The source table sourceTable contains the resource ID, resource type ID, and some original content data. A field A is added to the source table. If it is null, you must enter the content in field.
In order to improve the input efficiency, the source table sourceTable is divided into several tables (such as jobTable1, jobTable2....). The structure after table sharding is identical to that of the source table sourceTable. Each person is responsible for inputting one of the tables.
The following uses jobTable1 as an example to describe how to merge the entered data into the source table sourceTable.
We use the update statement to update a field for a table. How can we perform cross-Table update?
See the following SQL statement:
- UPDATE `sourceTable`,`jobTable1` SET `sourceTable`.`A` = `jobTable1`.`A` WHERE `sourceTable`.`ID` = `jobTable1`.`ID`ding.dingjian.org;
The preceding SQL statement updates the content of field A in Table sharding jobTable1 to the source table sourceTable, and masks the content of field A in the source table sourceTable.
Because the ID in the table sharding jobTable1 corresponds to the ID in the source table sourceTable, the WHERE clause is used to locate registration.
The UPDATE statement can not only UPDATE a single table, but also UPDATE across tables. It can also use the JOIN Outer JOIN syntax.
For more information about the MySQL database, see the following article: http://database.51cto.com/mysql.