MySQL UPDATE Query with Example
โก Smart Summary
MySQL UPDATE Query modifies existing rows in a table, changing one field or several fields in a single statement. This resource explains UPDATE syntax, WHERE filtering, worked examples on the members table, and the safeguards that prevent unintended mass updates.

What is the UPDATE Query?
The UPDATE MySQL command is used to modify rows in a table. The UPDATE query can change a single field or multiple fields at the same time. It can also be used to update a MySQL table with values taken from another table.
Why Use the UPDATE Query in MySQL?
Data rarely stays correct forever. Members change phone numbers, prices change, and orders move from pending to shipped. Deleting the old row and inserting a replacement would break the primary key and any foreign key references. The UPDATE statement edits the row in place, so identity and relationships survive the change.
The UPDATE query is the right tool whenever:
- A value is wrong or outdated: Correct a misspelt name or refresh a contact number without touching the rest of the record.
- A status must move forward: Flip an order from “pending” to “shipped” by rewriting a single column.
- Several fields change together: One statement can set a new name and a new address in the same pass.
- A bulk correction is needed: A WHERE clause that matches many rows applies the same edit to all of them at once.
Because an UPDATE without a WHERE clause rewrites every row, the filter separates a routine correction from an accidental overwrite.
MySQL Update Command Syntax
With the purpose established, the next step is the syntax. The basic form of the UPDATE query in MySQL is shown below.
UPDATE `table_name` SET `column_name` = 'new_value' [WHERE condition];
HERE:
- UPDATE `table_name` is the command that tells MySQL to modify the data in a table.
- SET `column_name` = ‘new_value’ gives the names and values of the fields to be affected by the UPDATE query. When setting the values, string data types must be in single quotes. Numeric values do not need quotation marks. Date values must be in single quotes and in the ‘YYYY-MM-DD’ format.
- [WHERE condition] is optional and can be used to apply a filter that restricts the number of rows affected by the UPDATE query. The full option list appears in the MySQL UPDATE Statement manual.
Let’s now look at a practical example that updates data in the members table.
Update in MySQL Example
Suppose the members with membership numbers 1 and 2 have the following updates to be made to their records.
| Membership number | Updates required |
|---|---|
| 1 | Change contact number from 999 to 0759 253 532 |
| 2 | Change the name to Janet Smith Jones and update the physical address to Melrose 123 |
Update a Single Column
We start with membership number 1. Before making any change, let’s retrieve that record.
SELECT * FROM `members` WHERE `membership_number` = 1;
Executing the above script gives us the following results.
| membership_number | full_names | gender | date_of_birth | physical_address | postal_address | contact_number | |
|---|---|---|---|---|---|---|---|
| 1 | Janet Jones | Female | 21-07-1980 | First Street Plot No 4 | Private Bag | 999 | janetjones@yagoo.cm |
Let’s now update the contact number using the script shown below.
UPDATE `members` SET `contact_number` = '0759 253 532' WHERE `membership_number` = 1;
Executing the above script changes the contact number from 999 to 0759 253 532 for membership number 1. Re-running the SELECT confirms the new value.
| membership_number | full_names | gender | date_of_birth | physical_address | postal_address | contact_number | |
|---|---|---|---|---|---|---|---|
| 1 | Janet Jones | Female | 21-07-1980 | First Street Plot No 4 | Private Bag | 0759 253 532 | janetjones@yagoo.cm |
Update Multiple Columns
Membership number 2 needs two fields changed at once. This is the record before the update.
| membership_number | full_names | gender | date_of_birth | physical_address | postal_address | contact_number | |
|---|---|---|---|---|---|---|---|
| 2 | Smith Jones | Female | 23-06-1980 | Park Street | NULL | NULL | jj@fstreet.com |
The following script updates both columns in one statement. Note the comma separating the two assignments.
UPDATE `members` SET `full_names` = 'Janet Smith Jones', `physical_address` = 'Melrose 123' WHERE `membership_number` = 2;
Executing the above script updates the full names for membership number 2 to Janet Smith Jones and the physical address to Melrose 123.
| membership_number | full_names | gender | date_of_birth | physical_address | postal_address | contact_number | |
|---|---|---|---|---|---|---|---|
| 2 | Janet Smith Jones | Female | 23-06-1980 | Melrose 123 | NULL | NULL | jj@fstreet.com |
๐ก Tip: The “WHERE clause” is what limits the number of rows affected by the UPDATE query. Omit it and every row in the table is rewritten.
