MySQL
SQL query
database management
multi-table update
relational databases

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.

Practice system design

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:

sql
1UPDATE table1 AS t1
2JOIN table2 AS t2 ON t1.id = t2.table1_id
3SET t1.status = 'processed',
4    t2.synced = 1
5WHERE t1.id = 42;

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.

sql
1UPDATE orders AS o
2JOIN inventory AS i ON o.product_id = i.product_id
3SET o.status = 'shipped',
4    i.quantity = i.quantity - o.quantity
5WHERE o.order_id = 1001;

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.

sql
1START TRANSACTION;
2
3UPDATE orders AS o
4JOIN inventory AS i ON o.product_id = i.product_id
5SET o.status = 'shipped',
6    i.quantity = i.quantity - o.quantity
7WHERE o.order_id = 1001;
8
9COMMIT;

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.

sql
1SELECT o.order_id, o.status, i.quantity
2FROM orders AS o
3JOIN inventory AS i ON o.product_id = i.product_id
4WHERE o.order_id = 1001;

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 UPDATE with JOIN is supported and often the right tool.
  • Running a joined update without first checking the row set with SELECT risks changing far more rows than intended. Verify the join before the write.
  • Omitting a restrictive WHERE clause 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 JOIN defines the related rows, and the SET clause can modify columns in more than one table.
  • A quick SELECT with 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.