Skip to content

Modifying existing records in a MySQL database is crucial for keeping the data current and accurate. This guide will show you how to use the UPDATE statement effectively to change data within your tables. The UPDATE statement is your go-to for altering values in one or several columns for a single row or multiple rows at once.

What is the basic syntax of the UPDATE statement?

You’ll follow this syntax for the UPDATE statement:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Here, table_name is where you want to make updates, SET column1 = value1, column2 = value2, ... tells which columns to update and their new values, and WHERE condition directs the updates to specific rows. Omitting the WHERE clause updates all rows in the table.

How do you update a single column?

To change a single column, you just list one column/value pair in the SET clause. For updating a user’s email by their ID, you would do:

UPDATE users
SET email = '[email protected]'
WHERE id = 1;

How can you update multiple columns at once?

For multiple column updates, include several column/value pairs separated by commas in the SET clause. To update a user’s email and name simultaneously:

UPDATE users
SET email = '[email protected]', name = 'John Doe'
WHERE id = 1;

What role does the WHERE clause play in updates?

The WHERE clause is essential for pinpointing the rows that need updating. To give all “Engineering” department employees a 10% salary increase:

UPDATE employees
SET salary = salary * 1.10
WHERE department = 'Engineering';

How do you limit the number of rows updated?

To restrict the number of updated rows, use the LIMIT clause. This is helpful for large-scale tests before a full update. For example, to decrease the price of 10 “Electronics” category products by 10%:

UPDATE products
SET price = price * 0.90
WHERE category = 'Electronics'
LIMIT 10;

By actively engaging with the UPDATE statement, you gain a powerful tool for data management in MySQL. Remember, precise targeting with the WHERE clause prevents unintended data alterations. Always back up your data before performing widespread updates to safeguard against data loss.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.