MySQL, update multiple tables with one query
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
MySQL can update multiple tables in a single statement by using a multi-table UPDATE with JOIN. This is useful when related rows in different tables must be changed together, but it should be used carefully because one statement can affect a lot of data at once.
Basic Multi-Table UPDATE Syntax
The MySQL pattern looks like this:
This updates matching rows in both table1 and table2. The JOIN determines which rows participate, and the SET clause can assign columns from either joined table.
That is the direct answer to the question. You do not need two separate UPDATE statements if the rows are related and can be matched in one join.
Example with Orders and Inventory
Suppose you want to mark an order as shipped and decrease inventory for the referenced product.
This changes both tables in one statement. It is concise, and it keeps the intent visible in a single query.
Why a Transaction Still Matters
Even when MySQL allows a multi-table update, you should still think transactionally. If the business operation is important, run it in a transaction so related reads and writes stay consistent with the rest of the workflow.
The multi-table update is one statement, but the surrounding transaction can still matter if the operation is part of a larger unit of work.
Not Every Multi-Table Change Belongs in One Statement
Sometimes two separate statements are clearer or safer, especially when:
- the tables are related indirectly
- different validation rules apply to each write
- the update logic is easier to audit step by step
- the affected row sets are not defined by a clean join
The fact that MySQL can do a multi-table update does not mean it is always the best design. Use it when the join logic is direct and the shared update really is one coherent operation.
Test the JOIN First
Before running the update, run the same join as a SELECT.
This is the safest habit when writing a multi-table update. If the select returns the wrong rows, the update will too.
Common Pitfalls
- Assuming MySQL cannot update multiple tables in one statement is incorrect. Multi-table
UPDATEwithJOINis supported and often the right tool. - Running a joined update without first checking the row set with
SELECTrisks changing far more rows than intended. Verify the join before the write. - Omitting a restrictive
WHEREclause can turn a targeted update into a bulk data change across multiple tables. Be explicit about scope. - Treating a multi-table update as a replacement for transaction design can still leave larger workflows inconsistent. Use transactions when the business operation spans more than one logical step.
- Writing a complex joined update when two simpler statements would be clearer can make maintenance harder. Use one statement only when it genuinely improves correctness or clarity.
Summary
- MySQL supports updating multiple tables in one statement with
UPDATE ... JOIN. - The
JOINdefines the related rows, and theSETclause can modify columns in more than one table. - A quick
SELECTwith the same join is the safest way to verify the target rows first. - Transactions still matter when the update is part of a larger business operation.
- Use multi-table updates when the relationship is direct and the combined change is logically one unit.
Related reading
- MySQL user DB does not have password columns - Installing MySQL on OSX
- MySQL variable vs. variable. What's the difference?
- MySQL vs MongoDB 1000 reads
- MySQL vs MySQLi when using PHP
- MySQL vs PostgreSQL for Web Applications
- MySQL What is a page?
- MySQL What's the difference between float and double?
- MySQL with Node.js

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.