Home >Database >Mysql Tutorial >How to Update a MySQL Table Using Data from Another Table?
Updating MySQL Table Based on Values from Another Table
Objective:
The task is to update values in one MySQL table (Table2) using data from another table (Table1) based on matching values between specific columns.
Tables:
Matching Criteria:
Update Query:
To achieve the required update, use the following SQL query:
UPDATE Table2 JOIN Table1 ON Table2.SERIAL_ID = Table1.SUBST_ID SET Table2.BRANCH_ID = Table1.CREATED_ID;
Explanation:
Result:
After executing this query, Table2 will be updated with the 'BRANCH_ID' values retrieved from Table1 based on the matching 'SERIAL_ID' values. The resulting Table2 will be as follows:
The above is the detailed content of How to Update a MySQL Table Using Data from Another Table?. For more information, please follow other related articles on the PHP Chinese website!