SyntaxStudy
Sign Up
MySQL Intermediate 6 min read

UPDATE with JOIN

MySQL supports updating rows in one table based on data from another table using a JOIN inside the UPDATE statement. This is powerful when the new values or the filter condition depend on a related table.

Syntax

The JOIN is placed between the table name and the SET clause. You can use INNER JOIN, LEFT JOIN, or other join types depending on your needs. The WHERE clause can reference columns from both tables.

A common use case is syncing data between tables — for example, updating a summary table based on aggregated values from a detail table, or applying a price list from a reference table to a products table.

Important Notes

  • Only the rows in the first table (after UPDATE) are modified
  • The join table is used only for filtering or supplying values
  • Aliases make the query easier to read
  • Test the equivalent SELECT JOIN first to confirm results
Example
UPDATE orders o
INNER JOIN customers c ON o.customer_id = c.id
SET o.discount = 0.10
WHERE c.membership_level = 'gold'
  AND o.created_at >= '2025-01-01';
Pro Tip

Prefer INNER JOIN when you only want to update rows that have a matching record in the join table.